loop through string

can someone tell me how to loop through a string and uppercase each letter?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <string>
#include <cctype>
#include <iostream>
#include <algorithm>

int main()
{
    std::string str = "loop through a string and uppercase each letter\n" ;

    for( char& c : str ) c = std::toupper(c) ; // 1
    std::cout << str ;

    for( std::string::iterator iter = str.begin() ; iter != str.end() ; ++iter ) // 2
          *iter = std::tolower( *iter ) ;
    std::cout << str ;

    for( std::string::size_type i = 0 ; i < str.size() ; ++i ) // 3
          str[i] = std::toupper(str[i]) ;
    std::cout << str ;

    std::transform( str.begin(), str.end(), str.begin(), ( int(*)(int) )std::tolower ) ; // 4
    std::cout << str ;
}


http://ideone.com/b47lJF
Topic archived. No new replies allowed.