Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

convert dec (int ) to hex (str)

Status
Not open for further replies.

redeye20448

Programmer
Dec 8, 2004
2
BE

Hi all, I'm advanched in VB but beginner in C++, how can I convert a int number to a hex number and put it in a string?

basiclly i wanna do this;

int iR = 255;

string sR;
sR = ""; // convert iR to hex and put it in sR

return sR;

Thanks at front.
 
Code:
  int iR = 255;
  char hex[20];
  itoa(iR,hex,16);
  string sR = hex;

/Per

"It was a work of art, flawless, sublime. A triumph equaled only by its monumental failure."
 
Do it like this:

Code:
stringstream s;
s << hex << 255;
string str = s.str();
 

Thanks PerFnurt, that works, thanks to you to timmay3141.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top