c++ - Convert String from Edit control box to Hex value
问题描述
I am using .net application for GUI to communicate with the board ,
I have converted the data from edit box to string using GetWindowText(). ex:"478B4119" to "0x478B4119" but i want 0x478B4119 as unsinged int ,as i want to used it as an address and pass to the function to read the value in the address The function : read(unsigned int add,unsigned char size) obviously i cant pass string to the function.
解决方案
您可以使用std::stringstream
#include <iostream>
#include <sstream>
void read(unsigned int add) {
std::cout << add;
}
int main() {
unsigned int x;
std::stringstream ss;
ss << std::hex << "478B4119"; //your string => 478B4119
ss >> x;
read(x);
}
输出:
1200308505 //this number is equal to your string (478B4119) in hex
现在您可以将字符串作为参数发送给unsigned int
参数化函数。
推荐阅读
- node.js - 快速中间件的超时问题
- python - 熊猫 python 3.7 上的热图
- javascript - 编辑内容后网站无法运行
- python - 从 Docker 运行 Python
- firebase - 如何使用 Flutter 从 Firebase Login 打印 PlatformException 的用户可读部分?
- sml - 从字符串中删除字符的 SML 程序
- css - 为什么当我制作元素位置时线性梯度消失:绝对?
- java - 如何从文本导入到数组中,不包括文本文件中的某些字符
- django - 如何在 django 中将文件保存到外键模型
- c++11 - 将二维字符向量传递给函数时出现分段错误