第一种方法使用for进行遍历
for(auto &str : input)
{
....
}
第二种方法使用transform函数和字符串迭代器进行遍历
transform(input.begin(), input.end(), input.begin(), ::toupper);
使用vs2017(15.7)测试通过的完整代码
#include "stdafx.h"
#include "InstallDriver.h"
#include <algorithm>
using namespace std;
int main()
{
string input;
cout << "Input Y(Yes),Install Driver!" << endl;
cin >> input;
for(auto &str : input)
{
str = ::tolower(str);
}
cout << input << endl;
transform(input.begin(), input.end(), input.begin(), ::toupper);
cout << input << endl;
return 0;
}