std::string trimmed after 101 characters

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

  1. macrumors newbie

    Joined:
    Feb 12, 2009
    #1
    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
     
  2. macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #2
    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
     
  3. thread starter macrumors newbie

    Joined:
    Feb 12, 2009
    #3
    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 member

    Joined:
    Sep 17, 2008
    #4
    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?
     
  5. macrumors 6502a

    Joined:
    Sep 3, 2005
    Location:
    Cramlington, UK
    #5
    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
     

Share This Page