How to Convert a C++ String to Uppercase

前端 未结 6 1750
不知归路
不知归路 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:00

    Try this small program, straight from C++ reference

    #include 
    #include  
    #include   
    #include 
    #include 
    
    using namespace std;
    
    int main()
    {
        string s;
        cin >> s;
        std::transform(s.begin(), s.end(), s.begin(), std::ptr_fun(std::toupper));
        cout << s;
        return 0;
    
    }
    

    Live demo

提交回复
热议问题