在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問(wèn)答/C++/ c++ 迭代器,使用while時(shí)陷入死循環(huán)?

c++ 迭代器,使用while時(shí)陷入死循環(huán)?

#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;
}

在學(xué)習(xí)c++primer迭代器這一節(jié)時(shí),要求是把上面程序的字符串s全部改為大寫(xiě),書(shū)上用的是for循環(huán),我試著使用while,但是編譯通過(guò)了, 執(zhí)行的時(shí)候不顯示結(jié)果,ctrl+D 沒(méi)反應(yīng), 只能ctrl+Z或ctrl+C強(qiáng)制結(jié)束。
想問(wèn)一下, 我的程序有是語(yǔ)法上的錯(cuò)誤, 還是迭代不支持while
謝謝

回答
編輯回答
初念
#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()) {
            *it = toupper(*it);
            it++;
        }
        cout << s << endl;
    }
    return 0;
}

經(jīng)過(guò)評(píng)論區(qū)@zhenguoli 的提示改正了

2018年5月10日 18:02