How to add space to string at certain place in C++

1 Answer

0 votes
#include <iostream>
 
int main() {
    std::string str = "C++ Is A ProgrammingLanguage";
    std::string tmp = "";
    int size = str.length();
 
    tmp += str[0];
 
    for (int i = 1; i < size; i++) {
        if (str[i] == 'L') {
            tmp += ' ';
        }
        tmp += str[i];
    }
 
    std::cout << tmp;
}
 
 
 
 
/*
run:
 
C++ Is A Programming Language
 
*/

 



answered Apr 30, 2022 by avibootz
...