Hi,
I want to convert a string to hexadecimal in vc++. Is there any built in function in vc++ to do this. I am working on visual studio 2008. Just like VB has some in built some in built function. otherwise if there are no built in functions, any code which anyone can share is appreciated.
Thanks & Regards,
P.Karthik
Loading
VulpesPosted Sep 14, 2011, 5:31 AM
String ^myString = L"The quick brown fox";
for each(Char c in myString) Console::Write("{0:x2} ", (int)c);
Sam HobbsPosted Sep 14, 2011, 4:16 PM
Nore that the comment "working on vc++ not c++" does not make sense. Traditionally VC is both the compiler and the VS IDE, but the compiler is C++!
In the future please specify whether you want a C, C++ or .Net solution. I say C or C++ since there is often an overlap in functions. For example, strings in C are char[] and in C++ (standard classes) they are std::string.
Sam HobbsPosted Sep 14, 2011, 4:02 PM
Look at the _itoa, _i64toa, _ui64toa, _itow, _i64tow, _ui64tow functions; the third parameter is for the "radix".
Karthik AgarwalPosted Sep 14, 2011, 5:35 AM
Got it i was almost correct but was just trying with
{0:2X} as identifier where compiler is returning 2X as a output all the time. Silly mistake. Anyways thanks.
Karthik AgarwalPosted Sep 14, 2011, 5:30 AM
The problem is that i am working on vc++ not c++. If you just give answer related to .Net framework, i would appreciate that.
That too i want to write that converted hex value to file through stream writer, which i can do on my own.
Thanks.
Prabhu RajaPosted Sep 14, 2011, 5:26 AM
Try this
#include
#include
stringstream convert ( abc );
convert>> std::hex >> i;
------------------------------------------------------
If this Post Helps you, then mark as "Correct Answer"
Thank You