I'm getting inoput from a binary file, in hex.
And I want it to say the first nine characters... like "0x05 0x53,0x84 " ... and so on. So how do I turn a char in hex to a string in text?
azjherben
0
Light Poster
Recommended Answers
Jump to Postcin >> hex; //set the input stream to read in hexadecimal long num = 0; cin >> num; //input a number, example 15 cout<<hex<<showbase; // shows output as 0xsomeNumber cout << num; //prints 0xf instead of 15
you can do the same with ifstream iFile("number.txt")
or ofstream …
Jump to PostTry this...
#include <iostream> #include <string> #include <sstream> char HexStrToChar(std::string HexStr) { std::istringstream ist(HexStr); int value; ist >> std::hex >> value; return value; } int main() { std::string text = "0x05 0x53 0x84"; std::istringstream iss(text); while(iss >> text) { std::cout << HexStrToChar(text); } }
All 6 Replies
mrnutty
761
Senior Poster
Rkeast
azjherben
0
Light Poster
mrnutty
761
Senior Poster
azjherben
0
Light Poster
mrnutty
761
Senior Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.