C++ Standard Library: The string Class

The string class is part of the C++ standard library. A string represents a sequence of characters.

To use the string class, #include the header file:



	string s1;                //   s1 = ""                
string s2( "abcdef" ); // s2 = "abcdef"
string s3( s2 ); // s3 = "abcdef"
string s4( s2, 1 ); // s4 = "bcdef"
string s5( s2, 3, 2 ); // s5 = "de"
string s6( 10, '-' ); // s6 = "----------"

The string class also has a destructor that takes care of freeing the memory storing the characters when the object is destroyed.

Constant Member Functions:

These functions do not modify the string.

Operators Defined for string:

Member Functions: