首页 > 解决方案 > 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.

标签: c++.netdlltype-conversionhex

解决方案


您可以使用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参数化函数。


推荐阅读