Convert Character to Numeric ASCII

Ok so I need to write a translator program that will convert a single line of text from characters to their numeric ASCII equivalent. Here is an example:

Attack at dawn! becomes:
41747461636b206174206461776e21

I know the best way to make this conversion is one character at a time but my question is how do I turn the character into its numeric equivalent? I can't imagine I should actually make a giant ifelse clause saying 41 is A and 42 is B etc... Any ideas?
Last edited on
No need, just convert each character to an int:
1
2
  string str="Attack at dawn!";
  for(char c : str)cout << hex << int(c);
for(char c : str) cout << hex << int(c);


Hi is the above for loop a new syntax in C++ ? Java has it in 1.5 onwards and now standard C++ has it also ? :O
Not yet, but it will when C++0x becomes the official standard.
I just didn't feel like typing it out.
Not yet, but it will when C++0x becomes the official standard.
I just didn't feel like typing it out.


Don't you feel C++ standards is always abit slow in becoming official compared to Java ? Even getting those Boost libraries to be incorporated into C++ standard take so long. The business world wait for no one.

I believe if C++ standard committee can be fast in approving the standards, C++ really can be a "business-centric" programming language. Currently, Java seems to hog the lime-light with all their wonderful "business-centric API". For e.g, they have a ready-to-use XML parser API so when can I see that in C++ standard ? :P
Topic archived. No new replies allowed.