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>>; ...