たこすの競プロライブラリメモ

C++の個人的競プロライブラリです。99%拝借。

大文字・小文字変換 (toupper, tolower)

目的

stringの文字列を大文字または小文字に揃える。

コード

string s;

transform(s.begin(), s.end(), s.begin(), ::toupper);//大文字に変換
transform(s.begin(), s.end(), s.begin(), ::tolower);//小文字に変換

コードテスト

#include <bits/stdc++.h>
using namespace std;

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);

  string s("Yahoo Google");

  transform(s.begin(), s.end(), s.begin(), ::toupper);
  cout << s << endl;
  transform(s.begin(), s.end(), s.begin(), ::tolower);
  cout << s << endl;
 }
YAHOO GOOGLE
yahoo google

出典

teratail.com