Some string class methods and operators

Method prototype/operatorExplanationExample
string()default constructor; creates an empty stringstring str1;
void assign(string str)this string becomes strstr1.assign(str2)
=same as assignstr1 = str2
>>extraction operator; ignores leading whitespace and extracts and stores characters until whitespace is foundcin >> str1
<<insertion operatorcout << str1
void getline(istream& iStr, string& str)extracts and stores all characters, including whitespace, from the stream,iStr, through the next new line (\n) character. The newline character is extracted but not stored. Note that this is not a member function so the dot(.) operator is not used.getline(cin, str1)
void getline(istream& iStr, string& str, char delimiter)extracts and stores all characters, including whitespace, from the stream,iStr, through the next delimiter. The delimiter is extracted but not stored. Note that this is not a member function so the dot(.) operator is not used.getline(cin,str1,':')
==equality operatorstr1 == str2
!=inequality operatorstr1 != str2
<less than operatorstr1 < str2
<=less than or equal operatorstr1 <= str2
>greater than operatorstr1 > str2
>=greater than or equal operatorstr1 >= str2
int length()returns the number of characters in this stringi = str1.length()
char at(int pos)returns the character at position pos. Remember that strings start at position 0!c = str1.at(5)
int find(string str)returns the position of the first occurrence of str in this string. Returns string::npos if str is not found.i = str1.find(str2)
void insert(int start, string str)insert str into this string starting at position startstr1.insert(5,str2)
void erase(int start, int n)erase the next n characters from this string starting at position startstr1.erase(5,8)
void replace(int start, int n, string str)replace the next n characters, starting at position start, with str. str1.replace(5,6,str2)
void assign(string str, int start, int n) this string becomes the substring of str, starting at position start and n characters long. str1.assign(str2,5,6)