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

VulpesRank #55 · 29.2K reputationPosted Sep 14, 2011, 1:31 AM EDT
String ^myString = L"The quick brown fox";
for each(Char c in myString) Console::Write("{0:x2} ", (int)c);
Prabhu RajaRank #861 · 2.6K reputationPosted Sep 14, 2011, 1:26 AM EDT
Try this
#include
#include
stringstream convert ( abc );
convert>> std::hex >> i;
------------------------------------------------------
If this Post Helps you, then mark as "Correct Answer"
Thank You
Karthik AgarwalRank #2,270 · 620 reputationPosted Sep 14, 2011, 1:30 AM EDT
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.
Karthik AgarwalRank #2,270 · 620 reputationPosted Sep 14, 2011, 1:35 AM EDT
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.
Sam HobbsRank #107 · 20.5K reputationPosted Sep 14, 2011, 12:02 PM EDT
Look at the _itoa, _i64toa, _ui64toa, _itow, _i64tow, _ui64tow functions; the third parameter is for the "radix".
Sam HobbsRank #107 · 20.5K reputationPosted Sep 14, 2011, 12:16 PM EDT
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.