Jump to content
  • Advertisement
Sign in to follow this  
Rozik

std::string

This topic is 4562 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hey there, i seem to have trouble with std::string whenever i use a string that has a space in it my program crashes is there anything i have to consider when i have a longer string that has spaces in it?

Share this post


Link to post
Share on other sites
Advertisement
whitespace is treated special by things like >> (in default mode reading stops at whitespace - but this can be set different ways). for instance

cin >> name;

would NOT get a name like "Tom Jones";

Share this post


Link to post
Share on other sites
Quote:
Original post by Rozik
hey there,

i seem to have trouble with std::string

whenever i use a string that has a space in it my program crashes

is there anything i have to consider when i have a longer string that has spaces in it?


Any code? How does it "crash"? Does it not do what you want it to? Does it display some kinda of message?

How are you using the string?

Share this post


Link to post
Share on other sites
If you are tying to read a string with spaces from stdin, use

string s;
getline( cin, s );


That should do what you want. If this was not your problem, we will need more details.

Share this post


Link to post
Share on other sites
i am useing the string with dll

and i am getting an error in the dbgheap.c

i just read a few things and i guess strings and dll's are a bad idea

i guess i am going to try and replace my strings with char*

Share this post


Link to post
Share on other sites
It's probably just coincidence that it crashes if you use spaces.

It's a bad idea to pass STL objects across a DLL boundary, unless you're linking to the DLL version of the CRT. The reason is that the memory is allocated in different heaps, so you can't add / remove from the objects easily.
You can't allocate memory in a DLL and free it in the EXE, or vice-versa.

Anyway, if you link to the DLL version of the CRT, it's not a problem.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!