Hi :)
I am using basic replace function but getting some runtime error as below:-
terminate called after throwing an instance of 'std::out_of_range'
what(): basic_string::replace
Aborted
I already know the position where I should replace so don't need to find it. Can somebody tell me how to avoid this error ? :icon_evil:
Here is my code:-
#include<iostream>
#include<string.h>
#include<fstream>
#include <stdlib.h>
using namespace std;
int main(int argc ,char* argv[]){
string line1;
ifstream myFile(argv[1]);
if(! myFile){
cout << "Error opening file" << endl;
return -1;
}
while(! myFile.eof()){
getline(myFile, line1);
line1.replace(10, 1, "W");
cout << line1 << endl;
}
myFile.close();
return 0;
}
Thanks ;)