PDA

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




tagro82
Feb 12, 2009, 08:45 AM
Hello

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

Sample
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

~Tarun



lee1210
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?

-Lee

tagro82
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?

lazydog
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"
"aaaaaaaaaaaaaaaaaaaaaaaaaaa"
"aaaaaaaaaaaaaaaaaaaaaaaaaaa" ;


b e n