View Full Version : std::string trimmed after 101 characters

Feb 12, 2009, 08:45 AM

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


Feb 12, 2009, 08:48 AM
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?


Feb 12, 2009, 11:19 PM
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

MacRumors Guy
Feb 13, 2009, 04:13 AM
I could not reproduce your bug compiling this
#include <iostream>

int main ()
std::string test = "deasdasdasdeasdasdasdeasdasdasdeasdasdasdeasdasdasdeasdasdasdeasdasdasdeasdasdasdeasdasdasdeasdasdas deasdasdasdeasdasdasdeasdasdasdeasdasdasdeasdasdasdeasdasdasdeasdasdasdeasdasdasdeasdasdasdeasdasdas deasdasdasdeasdasdasdeasdasdasdeasdasdasdeasdasdasdeasdasdas";
std::cout << test << std::endl;
return 0;
} without flags.

What compiler flags are you using? Can you show us more code?

Feb 13, 2009, 06:11 AM
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