25. Capitalizing an article title

The function template capitalize(), implemented as follows, works with strings of any type of characters. It does not modify the input string but creates a new string. To do so, it uses an std::stringstream. It iterates through all the characters in the input string and sets a flag indicating a new word to true every time a space or punctuation is encountered. Input characters are transformed to uppercase when they represent the first character in a word and to lowercase otherwise:

template <class Elem>using tstring = std::basic_string<Elem, std::char_traits<Elem>,                                   std::allocator<Elem>>;template <class Elem>using tstringstream = std::basic_stringstream< Elem, std::char_traits<Elem>, std::allocator<Elem>>; ...

Get The Modern C++ Challenge now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.