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?

cin >> 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 oFile("numbers.txt");

change cout to oFile, and cin to iFile.

Member Avatar for Rkeast

Try 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);
   }
}

I can't use cin or cout, it's an SDL program.
Also, it's char TO string, not the other way around.

I can't use cin or cout, it's an SDL program.
Also, it's char TO string, not the other way around.

Explain a bit more. Why cant you use C++ with sdl.

I can just not cout and cin.

Are you using sdl to read in the file?

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.