How to replace all spaces in a string with specific character in C++

1 Answer

0 votes
#include <iostream>
#include <algorithm>

int main() {
    std::string s =  "    c++ python      c     java php   ";

    std::replace(s.begin(), s.end(), ' ', '*'); 

    std::cout << s;
}




/*
run:

****c++*python******c*****java*php***

*/

 



answered Feb 26, 2021 by avibootz
...