将字符串转换为大写字母时出现问题

lyc*_*con 3 c++

使用以下控制台应用程序我将每个字符串转换为大写字母.但输出中的字符串值保持不变.我在这做错了什么.此外,任何有效这方面的帮助将不胜感激.谢谢你的帮助.

int main()
{    

    vector<string> svec, svec_out;
    string word;
    int run;

    cout << "Press 0 to quit giving input string" << endl;

    while(1)
    {
        cin >> word;
        svec.push_back(word);

        cin >> run;
        if (!run)
            break;
    }

    cout << "converting to upper case... " << endl;

    int i;
    for (i = 0; i!=svec.size(); ++i)
    {
        word = svec[i];
        for (string::size_type j=0; j < word.size(); ++j)
        {
            toupper(word[j]);
        }

        svec_out.push_back(word);
    }


    for ( i = 0; i<svec_out.size(); i++)
        cout << svec_out[i] << endl;

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

fbr*_*eto 7

toupper将返回大写值而不是就地修改值.因此,您的代码应为:

word[j] = toupper(word[j]);
Run Code Online (Sandbox Code Playgroud)