Results 1 to 4 of 4

Thread: DWORD to CString

  1. #1

    Thread Starter
    Hyperactive Member noble's Avatar
    Join Date
    Nov 2000
    Location
    Philly
    Posts
    471

    DWORD to CString

    I'm converting a DWORD which represents a CRC to a string.

    This works fine but whenever the DWORD is preceded by a
    zero, it's truncated and not included in the string.

    Code:
    _itoa(dwChecksum, buffer, 16);
    Is there another way to do this without losing that first zero?
    Bababooey
    Tatatoothy
    Mamamonkey

  2. #2
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    You could always convert it, then see how many characters there are.

    Or, you could use a stringstream to do it for you:
    Code:
    #include <iostream>
    #include <sstream>
    #include <iomanip>
    
    void somecode() {
        ostringstream oss;
    
        oss << setw(8) << setfill('0') << 6574;
    
        string whatever = oss.str();
    }
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  3. #3

    Thread Starter
    Hyperactive Member noble's Avatar
    Join Date
    Nov 2000
    Location
    Philly
    Posts
    471
    thx, i had the value in a CString so i just tested to make sure the
    length was 8 and added a '0' otherwise
    Bababooey
    Tatatoothy
    Mamamonkey

  4. #4
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Or use the CString::Format function. I works like sprintf.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width