search

Home  >  Q&A  >  body text

c++ - cout << toupper(c);为什么打印时是一串数字?

    string s19 = "hello, world!";
    for(auto c: s19)
    {
        //输出大写形式
        if(!ispunct(c) || !isspace(c))
        {
            cout << toupper(c);
        }
    }
这样写打印时是一串数字。而如果像下面这样:
c = toupper(c);
cout << c;  
打印时则正确,请问大家这是怎么回事?

高洛峰高洛峰2804 days ago596

reply all(1)I'll reply

  • 天蓬老师

    天蓬老师2017-04-17 11:47:25

    The reason is simple.

    Please note the return value of toupper: http://www.cplusplus.com/reference/cctype/toupper/

    reply
    0
  • Cancelreply