C formatting codes in C++

This is a discussion on C formatting codes in C++ within the C++ Programming forums, part of the General Programming Boards category; When working with string streams and strings, how do you attain the same affect as the %02x format code from ...

  1. #1
    Registered User
    Join Date
    Aug 2007
    Posts
    81

    C formatting codes in C++

    When working with string streams and strings, how do you attain the same affect as the %02x format code from C?

    I want to take a byte of data and store it as its hexidecimal equivilent in ASCII into either a string or string stream.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    20,981
    You would use the std::hex manipulator for the hex output, std::setw(2) to set the field width to 2, and std::setfill('0') to set the fill character to '0'.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. codes
    By IfYouSaySo in forum A Brief History of Cprogramming.com
    Replies: 34
    Last Post: 11-18-2005, 02:09 PM
  2. dos game help
    By kwm32 in forum Game Programming
    Replies: 7
    Last Post: 03-28-2004, 05:28 PM
  3. action replay codes
    By c++.prog.newbie in forum Game Programming
    Replies: 2
    Last Post: 02-28-2004, 07:47 AM
  4. converting scan codes to ascii codes
    By stupid_mutt in forum C Programming
    Replies: 11
    Last Post: 01-25-2002, 03:06 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21