Jump to content
  • Advertisement
Sign in to follow this  

This topic is 3755 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

Don't make fun of me for this. I've been working on a 2D zelda like game for awhile. Suppose I've been using char[] arrays to store strings in and writing my own little functions to deal with them. Now say, I want to get with the times and use strings. Does c++ have a standard string library? I mean one that's going to compile on any machine? What library should I include? I vaguely remember something called a CString but also I think there was a competing string library. And then there's the STD Template library or whatever it's called. I think I'm going to start by reading about CStrings but if I'm barking up the wrong tree and someone wants to point me in the correct direction I'd appreciate it.

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by icecubeflower

And then there's the STD Template library or whatever it's called.


STL has (been) evolved into C++ standard library. For besic purposes, they are equivalent (although they are not, and some will get very upset over such claims).

CString, unless you intend to do WinAPI programming, has little use.



Relatively off-topic, but one of first page google links for "CString" links to an adult page....

Share this post


Link to post
Share on other sites
Hey thanks. But the one thing I never understood about strings is how big are they? When I declare a char array I say char name[20] or whatever and make it 20 bytes. But look at this:


string name ("John");
string family ("Smith");

name += " K. "; // c-string
name += family; // string
name += '\n'; // character

cout << name;

return 0;



So that will output "John K. Smith" and have an end line as the last character. How much stuff can you concatenate onto a string? Does it keep allocating more memory for itself?

Share this post


Link to post
Share on other sites
The string resizes itself automatically when it needs to. BTW, you cannot use += with characters. It should be:

name += "\n";
Sorry, that's incorrect. Not sure where I got that from.

Share this post


Link to post
Share on other sites
Quote:
BTW, you cannot use += with characters. It should be:
Yes, you can. You can append a string, and a character as well. So if you want to append a character, use ' ', not " ".

Quote:
How much stuff can you concatenate onto a string?
string::max_size() : Use max_size() on a string object to see how many characters it can have at maximum.

Share this post


Link to post
Share on other sites
I cut and pasted that code directly from the link you gave me. I think you're right though. +='/n' is like saying +=10 I think. We'll see.

Share this post


Link to post
Share on other sites
Quote:
Original post by Gage64
BTW, you cannot use += with characters. It should be:

name += "\n";


Eh? VS's and Borland's std::string implementations allow for operator+=(char). Is this a non-standard extension or something?

Share this post


Link to post
Share on other sites
Quote:
Original post by icecubeflower
I think you're right though. +='/n' is like saying +=10 I think.


Not in C++. In C, a single character literal was of type int. In C++ single character literals are of type char, I imagine precisely to allow overloading to work correctly.

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!