Skip to main content

9.9) Applying Algorithms To Strings


The string type has begin and end methods analogous to those of containers. Hence it is possible to invoke functions from the algorithms library on strings of text:

string text = "Hello World!";
reverse(text.begin(), text.end());
cout << text << endl;   // prints "!dlroW olleH"

See stringalg.cpp for a complete example.