Advertisement
Naohiro19

大文字を小文字に、小文字を大文字に変換(C++版)

Jan 24th, 2022
1,580
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <string>
  4. #include <cctype>
  5.  
  6. char toupper_and_tolower(char c)
  7. {
  8.     if (std::isupper(c)) {
  9.         c = (char)std::tolower(c);
  10.     }
  11.     else if (std::islower(c)) {
  12.         c = (char)std::toupper(c);
  13.     }
  14.     return c;
  15. }
  16.  
  17. int main()
  18. {
  19.     std::string s = "Yahoo Google";
  20.     std::string d;
  21.     d.resize(s.size());
  22.  
  23.     std::transform(s.begin(), s.end(), d.begin(), toupper_and_tolower);
  24.     std::cout << s << std::endl;
  25.     std::cout << d << std::endl;
  26.  
  27. }
  28.  
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement