Thread: c_str() truncating string (randomly?)

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Jan 2011
    Posts
    4
    Quote Originally Posted by tabstop View Post
    If it was a space, you wouldn't have a problem. I'm guessing you have an actual \0 character, which is not at all like a space, really.

    Are you still doing those debug print statements I see posted here? Is o short, or just o.c_str? If your strings are always supposed to be the same length, you could do
    Code:
    for (int k = 0; k < string_length; k++) {
        cout << static_cast<int> o[k] << " ";
    }
    to see the actual values of the characters.
    Yep I am, that was where I got these from:

    Normal String: ",1 2 3m4 5 6 7 8 q X - = [ ].C ' # f . /"
    Converted: ",1 2 3m4 5 6 7 8 q X -"
    Thanks for the help, I will try what you suggest and see what I get

  2. #2
    Registered User
    Join Date
    Jan 2011
    Posts
    4

    Thumbs up

    Thanks so much you were right, turns out the range of random numbers I was generating was one larger than my character dictionary, so every now and then it would reach outside it and get that \0 value

    Thanks again for all your help!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. OOP Question DB Access Wrapper Classes
    By digioz in forum C# Programming
    Replies: 2
    Last Post: 09-07-2008, 04:30 PM
  2. Please check my C++
    By csonx_p in forum C++ Programming
    Replies: 263
    Last Post: 07-24-2008, 09:20 AM
  3. Message class ** Need help befor 12am tonight**
    By TransformedBG in forum C++ Programming
    Replies: 1
    Last Post: 11-29-2006, 11:03 PM
  4. Classes inheretance problem...
    By NANO in forum C++ Programming
    Replies: 12
    Last Post: 12-09-2002, 03:23 PM
  5. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 06:49 PM