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 134 views
1 answer 172 views
1 answer 129 views
1 answer 116 views
1 answer 106 views
1 answer 115 views
1 answer 114 views
...