25/10/2019

[C++] Convert string to lower or upper case

While playing with the Rock, Paper, Scissors game, I had to convert a given string to lower case. Turns out, C++ does not have a very straightforward way of doing so, but I found this solution works well since I am not dealing with strange locales:

 #include <iostream>  
 #include <algorithm>  
 #include <string>  
   
 std::string input;  
   
 std::getline(std::cin, input);  
      
 std::transform(input.begin(), input.end(), input.begin(), ::tolower);  

No comments:

Post a Comment

With great power comes great responsibility