将C++中的string中的字母全部转化成大写字母,用transform()方法
#include <iostream>
#include <string>
#include <algorithm>
#include <cctype>
using namespace std;
char toUpper(char ch){ return toupper(ch);}
void tf(string &s){
transform(s.begin(),s.end(),s.begin(),toUpper);
}
int main(){
string s = "abC$";
tf(s);
cout << s <<endl;
}
有点短,嘻嘻...