Standard Library (STL)

C++ Standard Library defines powerful, template-based, reusable components that implement many common data structures and algorithms used to process those data structures. The Standard Library consist of the three key components **containers**, **iterators**, and **algorithms**.

Binary Function
When you define your own binary functions to use with STL algorithms, you derive them from these classes in order to automatically get all the typedefs.

Now you don't need to manually provide the typedefs for argument_type, result_type etc. These structs, just like the iterator struct are there just for our convenience, in order to reuse the typedefs needed for algorithms

Comparisons
Strings can be compared to strings of their own type and to arrays of characters with the same character type.

Thus, s.compare(s2) returns 0 if the strings have the same value, a negative number if s is lexicographically before s2, and a positive number otherwise.

The ususal comparison operators ==, !=, >, <, >=, and <= are provided for basic_strings:

Comparison operators are nonmember functions so that conversions can be applied in the same way to both operands. The versions taking C-style strings are provided to optimize comparisons agains string literals.

Insert and Concatenation
Of the operations that modify the value of a string, is one of the most common is appending to it - that is, adding characters to the end. Insertion at other points of a string is rarer:

Concatemation - constructing a string out of two strings by placing one after the other - is provided by the + operator:

Find
There is a bewildering variety of functions for finding substrings:
 * Find subsequence, e.g. search
 * Find subsequence searching backwards from the end, e.g. find_end
 * Find character, e.g. find_first_of
 * Find character from argument searching backwards from the end
 * Find character not in argument
 * Find character not in argument searching backwards from the end

These are all **const** members. They exist to locate a substring for some use, but they do not change the value of the string to which they are applied.

Replace
Once a position in a string is identified, the vlaue of indvidual character positions can be changed using subscripting or whole substrings can be replaced with new characters:


 * Replace [ (*this)[i], (*this)[i + n] [ with other characters
 * Remove characters from string ("replace with nothing")

Note that the number fo new characters need not be the same as the number of characters previously in the string. The size of the string is changed to accomodate the new substring. In particular, erase simply removes a substring and adjusts its size accordingly.

Substrings
The substr funciton is simply a way of reading a part of a string. On the other hand, replace lets you write to a substring. Both rely on the low-level position plus number of characters notation. However, find lets us find bustrings by value. Together, they allow us to define a substring that can be used for both reading and writing.

I/O Operations
One of the main uses of strings is as the target of input and as the source of output. The << operator writes a string to an ostream. The >> operator reads a whitespace-terminated word to its string, expanding the string as needed to hold the word. Initial whitespace is skipped, and the terminating whitespace character is not entered into the string.

The getline function reads a line terminated by eol to its string, expanding string as needed to hold the line. If no eol argument is provided, a newline \n is used as the delimiter. The line terminator is removed from the stream but not entered into the string.

The getchar returns the next character from the standard input (stdin). It is equivalent to getc(stdin).

The putchar writes character to the current position in the standard output (stdout) and advances the internal file position indicator to the next position. It is equivalent to putc(character, stdout).

Conversion
From number to string:

From string to number:

From lowercase to uppercase: