How to replace the first N characters in a string in C++

1 Answer

0 votes
#include <iostream>

int main() {
    std::string str = "pro c++";
  
    int N = 3;
        
    str.replace(0, N, "XYZ");

    std::cout << str;
}




/*
run:

XYZ c++

*/

 



answered Jun 12, 2022 by avibootz

Related questions

2 answers 149 views
1 answer 184 views
1 answer 140 views
1 answer 127 views
1 answer 131 views
1 answer 126 views
1 answer 122 views
...