std::string trimmed after 101 characters

Discussion in 'Mac Programming' started by tagro82, Feb 12, 2009.

  1. tagro82 macrumors newbie

    Feb 12, 2009

    I am using std::string variable of huge length.
    Whenever I run the code on XCode, the variable gets trimmed at 101 characters.
    The same code on Visual Studio works fine

    std::string variable = "1111111....1a11"; //Say it has more than 101 characters where 'a' represents 101 character

    My strings gets trimmed at 101 character.

    Same code in VS Project is working fine.

    Can anyone help me in this

  2. lee1210 macrumors 68040


    Jan 10, 2005
    Dallas, TX
    You're saying that the string literal is somehow being truncated, but the code compiles OK?

    Or the code doesn't compile complaining that there's an unterimnated string constant?

    Have you tried compiling directly with g++ to see how it goes?

  3. tagro82 thread starter macrumors newbie

    Feb 12, 2009
    Compiling is fine. there is no issue with compile. At run time the string gets truncated.
    I tried each and everything (g++) but issue still reproducible
  4. MacRumors Guy macrumors member

    Sep 17, 2008
    I could not reproduce your bug compiling this
    #include <iostream>
    int main ()
    	std::string test = "deasdasdasdeasdasdasdeasdasdasdeasdasdasdeasdasdasdeasdasdasdeasdasdasdeasdasdasdeasdasdasdeasdasdasdeasdasdasdeasdasdasdeasdasdasdeasdasdasdeasdasdasdeasdasdasdeasdasdasdeasdasdasdeasdasdasdeasdasdasdeasdasdasdeasdasdasdeasdasdasdeasdasdasdeasdasdasdeasdasdas";
    	std::cout << test << std::endl;
    	return 0;
    without flags.

    What compiler flags are you using? Can you show us more code?
  5. lazydog macrumors 6502a

    Sep 3, 2005
    Cramlington, UK
    You could try splitting the string literal up over several lines to make it more readable just in case there's a problem with your definition or something like that.

    std::string long_str = "aaaaaaaaaaaaaaaaaaaaaaaaaaa"
                                  "aaaaaaaaaaaaaaaaaaaaaaaaaaa" ;
    b e n

Share This Page