Noeud:Strings, Noeud « Next »:, Noeud « Previous »:Generic Algorithms and Function Objects, Noeud « Up »:libstdc++ and the Standard Template Library



Strings

Of all the classes available to us in the STL, perhaps the most immediately useful is string. Using strings is often a necessity in many programs, and breaking away from the traditional char * declarations and having to worry about memory allocation and freeing are some of the many pitfalls that can cause code to become buggy and unpredictable. The string class provides us with an easy-to-use interface, making string-handling much less complex. In addition, it enables us to perform many different operations that we have seen previously using iterators, function objects and generic algorithms. Because of this we can manipulate strings in a fairly complex way, without too much code.

There are two types of string available to us; string and wstring. wstring is the implementation of strings that use more than one byte per character, such as unicode characters. We'll only look at using string here.