tags:

views:

333

answers:

5

I have been learning C++ with some books from school that are from the 80's and I'm not really sure if they are strings in C++ or just really long arrays of type char. Can anyone help?

+10  A: 

Check out the standard library.

In the STL, you can find the std::string class, as well as a bunch of other useful classes.

The basic documentation can be found here:

http://www.sgi.com/tech/stl/

The string documentation can be found here:

http://www.sgi.com/tech/stl/basic_string.html

The beauty of these stl strings is that they delete themselves; so once you declare them, you can just let them go, and they will handle their own memory. That's true of other stl classes as well (Of course, if you declare a vector of pointers, the vector will get deleted, but the memory the pointers point to has to be handled as well; it's not a total panacea, but it works nicely if you keep that limitation in mind).

Finally, I've found that this book is a really good way to learn how to think in STL:

Effective STL

mmr
+14  A: 

There is a string container class in C++.

PolyThinker
+5  A: 

Yes there are strings in C++, someone's gone along and done all the work and coded them for you. They're not in the actual language but in a library called the Standard Template Library, which is practically always supplied along with the C++ compiler (which you probably already have). Internally they are represented with a char array, but it's done in a special way so if the string gets bigger it discards the small char array and makes a new, bigger one.

You should really get a newer book!

Ray Hidayat
+2  A: 

C++ have a std::string as @mmr points out.

Beside that, almost every class library / framework / toolkit offers (at lest ) one of it's own.

Besides that, almost every large c++ project you'll get a change to work on will have an String library.

All these are needed, because no single size fits all. Some wants lazy copying of data, some want fast insertion in the middle etc, some want UTF-8 etc..

In all probability, if you project does any serious string manipulation, you'll end up writing one of your own.

Vardhan Varma
A: 

In C++; a null terminated char array IS a string.

Having said that, like many others have pointed out, various libraries also have a string class to handle the common string manipulation functionality.

John MacIntyre