fork download
  1. #include <string>
  2. #include <cctype>
  3. #include <iostream>
  4. #include <algorithm>
  5.  
  6. int main()
  7. {
  8. std::string str = "loop through a string and uppercase each letter\n" ;
  9.  
  10. for( char& c : str ) c = std::toupper(c) ; // 1
  11. std::cout << str ;
  12.  
  13. for( std::string::iterator iter = str.begin() ; iter != str.end() ; ++iter ) // 2
  14. *iter = std::tolower( *iter ) ;
  15. std::cout << str ;
  16.  
  17. for( std::string::size_type i = 0 ; i < str.size() ; ++i ) // 3
  18. str[i] = std::toupper(str[i]) ;
  19. std::cout << str ;
  20.  
  21. std::transform( str.begin(), str.end(), str.begin(), ( int(*)(int) )std::tolower ) ; // 4
  22. std::cout << str ;
  23. }
  24.  
Success #stdin #stdout 0s 2984KB
stdin
Standard input is empty
stdout
LOOP THROUGH A STRING AND UPPERCASE EACH LETTER
loop through a string and uppercase each letter
LOOP THROUGH A STRING AND UPPERCASE EACH LETTER
loop through a string and uppercase each letter