C++字符大小写互转,输入一整行字符串
在C++中,tolower()函数是把字符串都转化为小写字母,toupper()函数是把字符串都转化为大写字母。getline()是输入一整行字符串,遇到空格不会停下,遇到回车停
tolower(),toupper()使用方法:
string a = "ASDFGHJKL";
string b = "asdfghjkl";
for (int i = 0; i < a.size(); i++)
a[i] = tolower(a[i]);
for (int i = 0; i < b.size(); i++)
b[i] = toupper(b[i]);
cout << "a:" << a << endl;
cout << "b:" << b << endl;
getline()使用方法:
string a;
getline(cin, a);
cout << "a:" << a << endl;