简体   繁体   中英

Isupper / tolower doesn't work

here's the problem, my program does not change uppercase letter to lowercase letter. I can not figure out why doesn't it.

#include <iostream>
#include <ctype.h>

using namespace std;

int main(){
    string str="hEhEhehe";
    for(int i=0;i<str.size();i++){
        if(isupper(str.at(i)))
            tolower(str.at(i));
    }
    cout << str;
    return 0;
}

You need to assign the value back to the index of the string.

if(isupper(str.at(i)))
        str[i] = tolower(str.at(i));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM