#include <iostream>
#include <string>
using namespace std;
int main() {
string s("some string");
if (s.begin() != s.end()) {
auto it = s.begin();
while (it != s.end() && !isspace(*it))
*it = toupper(*it);
it++;
cout << s << endl;
}
return 0;
}
在学习c++primer迭代器这一节时,要求是把上面程序的字符串s全部改为大写,书上用的是for循环,我试着使用while,但是编译通过了, 执行的时候不显示结果,ctrl+D 没反应, 只能ctrl+Z或ctrl+C强制结束。
想问一下, 我的程序有是语法上的错误, 还是迭代不支持while
谢谢
经过评论区@zhenguoli 的提示改正了