How to Convert a C++ String to Uppercase

前端 未结 6 1741
不知归路
不知归路 2021-02-01 05:34

I need to convert a string in C++ to full upper case. I\'ve been searching for a while and found one way to do it:

#include 
#include 

        
6条回答
  •  深忆病人
    2021-02-01 06:16

    You could do:

    string name = "john doe"; //or just get string from user...
    for(int i = 0; i < name.size(); i++) {
        name.at(i) = toupper(name.at(i));
    }
    

提交回复
热议问题