Convert a String In C++ To Upper Case

后端 未结 30 1538
一个人的身影
一个人的身影 2020-11-22 05:25

How could one convert a string to upper case. The examples I have found from googling only have to deal with chars.

30条回答
  •  心在旅途
    2020-11-22 06:12

    ALL of these solutions on this page are harder than they need to be.

    Do this

    RegName = "SomE StRing That you wAnt ConvErTed";
    NameLength = RegName.Size();
    for (int forLoop = 0; forLoop < NameLength; ++forLoop)
    {
         RegName[forLoop] = tolower(RegName[forLoop]);
    }
    

    RegName is your string. Get your string size don't use string.size() as your actual tester, very messy and can cause issues. then. the most basic for loop.

    remember string size returns the delimiter too so use < and not <= in your loop test.

    output will be: some string that you want converted

提交回复
热议问题