Thread: C formatting codes in C++

  1. #1
    Registered User
    Join Date
    Aug 2007

    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
    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'.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    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
    Replies: 34
    Last Post: 11-18-2005, 03:09 PM
  2. dos game help
    By kwm32 in forum Game Programming
    Replies: 7
    Last Post: 03-28-2004, 06:28 PM
  3. action replay codes
    By c++.prog.newbie in forum Game Programming
    Replies: 2
    Last Post: 02-28-2004, 08:47 AM
  4. converting scan codes to ascii codes
    By stupid_mutt in forum C Programming
    Replies: 11
    Last Post: 01-25-2002, 04:06 PM