Changing Case in Strings : string « String « C++






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

1.Define a string variable, assign a value and display it
2.string basics
3.copy constructor
4.A short string demonstration.A short string demonstration.
5.Extracting Words in Strings Delimited by Whitespace
6.Loop through the string array
7.Char Escapes