Saturday, January 17, 2009

Strings library

C++ Strings library

The C++ strings library provides the definitions of the basic_string class, which is a class template specifically designed to manipulate strings of characters of any character type. It also include two specific instantiations: string and wstring, which respectively use char and wchar_t as character types.

string String class (class)

The characteristics of characters taken into consideration in these classes are not only the type itself, but also a set of traits. These traits are defined by specializing the class template char_traits for the specific type. Default specifications exist for both char and wchar_t:

char_traits Character traits (class template)

This reference uses as a base the string class, even though this is only one of the possible template instantiations (we believe this provides a better readability):

A set of global functions provide some additional functionality for strings to interact either with other string objects or with objects of other types, mainly through the overloading of operators:

operator+ Add strings (function)
swap Swap contents of two strings (function)
comparison operators String comparison operators (function)

The header also declares some functions that extend the functionality of streams (iostream library) to string objects:

getline Get line from stream (function)
operator<< Insert string into stream (function)
operator>> Extract string from istream (function)
Notice that some other operators are also overloaded as members of class string (+=, =, []).

No comments:

Post a Comment