transform
toupper
tolower
场景:
1. 转换字符串大小写,只有C的toupper怎么办???
代码:
#include <stdlib.h>
#include <string.h>
#include <string>
#include <iostream>
#include <sstream>
#include <algorithm>
using namespace std;
int main(int argc, char const *argv[])
{
string str("abcdefghijklnmopqrstuvwxyz123");
std::transform(str.begin(),str.end(),str.begin(),::toupper);
cout << str << endl;
char str2[] = "abcdefghijklnmopqrstuvwxyz1234";
std::transform(str2,str2+26,str2,::toupper);
cout << str2 << endl;
return 0;
}
输出:
ABCDEFGHIJKLNMOPQRSTUVWXYZ123
ABCDEFGHIJKLNMOPQRSTUVWXYZ1234