Use an iterator with the STL transform() algorithm to convert a string to uppercase. - C++ STL

C++ examples for STL:string

Description

Use an iterator with the STL transform() algorithm to convert a string to uppercase.

Demo Code

#include <iostream>
#include <string>
#include <cctype>
#include <algorithm>
#include <vector>
using namespace std;
int main()/*  w  w w .ja  v a 2  s.  co m*/
{
   string strA("This is a test. another test test test");

   // Create an iterator to a string.

   string::iterator itr;

   // Use an iterator with the STL transform() algorithm to convert a string to uppercase.

   cout << "Use the STL transform() algorithm to convert a "  << "string into uppercase.\n";

   transform(strA.begin(), strA.end(), strA.begin(), toupper);

   cout << strA << "\n\n";

   return 0;
}

Result


Related Tutorials