Some string class methods and operators

Method prototype/operatorExplanationExample
=assign a string to this stringstr1 = str2
=assign a C-style string to this stringstr1 = "help"
>>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 newline (\n) character. The newline character is extracted but not stored. If a newline character is found, the extracted characters are stored in str. If not, i.e. iStr.eof() is true, then str is not changed. 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. If a delimiter character is found, the extracted characters are stored in str. If not, i.e. iStr.eof() is true, then str is not changed. 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! If pos is not a valid position, the program will Abort at runtime. This is an l-value, that is, it can be used on the left hand side of an assignment statement.c = str1.at(5)
str1.at(5) = 't'
c_str()convert the string to a C-style stringstr1.c_str()
+return the concatenated stringstr1 + str2;
str1 + "tion";
"con" + str1;
str1 + 'h';
'u' + str1;
+=append a string or character to this stringstr1 += str2;
str1 += "tion";
str1 += 'h';