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

2 Answers

0 votes
#include <iostream>

int main() {
    std::string s = "c++ programming";

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

    std::cout << s;
}



/*
run:

c++ Programming

*/

 



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

int main() {
    std::string s = "c++ programming";

    for (auto & ch: s) if (ch == 'm') ch = toupper(ch);

    std::cout << s;
}



/*
run:

c++ prograMMing

*/

 



answered Apr 6, 2021 by avibootz
...