How to lowercase specific character of a string in C++

2 Answers

0 votes
#include <iostream>

int main() {
    std::string s = "C++ PROGRAMMING";

    for (auto & ch: s) if (ch == 'M') ch = tolower(ch);

    std::cout << s;
}



/*
run:

C++ PROGRAmmING

*/

 



answered Apr 6, 2021 by avibootz
0 votes
#include <iostream>

int main() {
    std::string s = "C++ PROGRAMMING";

    s[4] = tolower(s[4]);

    std::cout << s;
}



/*
run:

C++ pROGRAMMING

*/

 



answered Apr 6, 2021 by avibootz

Related questions

1 answer 138 views
1 answer 205 views
2 answers 161 views
2 answers 161 views
2 answers 183 views
1 answer 150 views
...