Changing Case in Strings
#include <algorithm>
#include <cctype>
#include <iostream>
#include <string>
using namespace std;
inline
char my_tolower( char c )
{ return
static_cast<char>( tolower( static_cast<unsigned char>( c ) ) );
}
inline
char my_toupper( char c )
{ return
static_cast<char>( toupper( static_cast<unsigned char>( c ) ) );
}
int main( )
{
string book( "The C++ Programming Language, 3rd Edition" );
cout << "String:" << book << endl << endl;
transform( book.begin(), book.end(), book.begin(), my_toupper );
cout << "Big letters:" << book << endl << endl;
transform( book.begin(), book.end(), book.begin(), my_tolower );
cout << "Small letters:" << book;
}
Related examples in the same category