-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy patha12.cpp
More file actions
41 lines (41 loc) · 722 Bytes
/
a12.cpp
File metadata and controls
41 lines (41 loc) · 722 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include<iostream>
#include<fstream>
#include<cstdlib>
#include<algorithm>
using namespace std;
int main(int argc,char* argv[]){
ifstream in(argv[1]);
if(argc<4)
{
cout<<"\nInvalid arguments.";
exit(1);
}
if(!in){
cout<<"\nError in opening file.";
exit(1);
}
string replace_data=" ";
string old=argv[2];
string data;
int found;
while(in){
getline(in,data);
found=data.find(old);
while(data.find(old)<500){
data.replace(found,old.size(),argv[3]);
found=data.find(old);
}
replace_data=replace_data+data+"\n";
}
in.close();
ofstream out(argv[1]);
out<<replace_data<<endl;
out.close();
ifstream b(argv[1]);
while(b){
getline(b,data);
cout<<data;
}
b.close();
return 0;
}