Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

tagro82

macrumors newbie
Original poster
Feb 12, 2009
2
0
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

macrumors 68040
Jan 10, 2005
3,182
3
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?

-Lee
 

tagro82

macrumors newbie
Original poster
Feb 12, 2009
2
0
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

macrumors member
Sep 17, 2008
82
0
I could not reproduce your bug compiling this
Code:
#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?
 

lazydog

macrumors 6502a
Sep 3, 2005
709
6
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.

Code:
std::string long_str = "aaaaaaaaaaaaaaaaaaaaaaaaaaa"
                              "aaaaaaaaaaaaaaaaaaaaaaaaaaa"
                               "aaaaaaaaaaaaaaaaaaaaaaaaaaa"                           
                              "aaaaaaaaaaaaaaaaaaaaaaaaaaa" ;

b e n
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.