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 261 views
1 answer 276 views
1 answer 215 views
1 answer 209 views
1 answer 194 views
1 answer 201 views
1 answer 187 views
...