-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathWHITESPA.CPP
40 lines (38 loc) · 919 Bytes
/
WHITESPA.CPP
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
/* Copy the contents of one text file to another file,after removing all whitespaces. */
#include<iostream>
#include<fstream>
using namespace std;
int main()
{
ifstream ifile;
ifile.open("sample.txt"); //file from which data is read
if(!ifile)
{
cout<<"\n Error opening file! ";
exit(1);
}
ofstream ofile;
ofile.open("copy.txt"); //file into which data is copied
if(!ofile)
{
cout<<"\n Error opening file! ";
exit(1);
}
char c;
cout<<"\n Content of the first file: "<<endl<<' ';
while(ifile.get(c)) //to read one character at a time
{
cout<<c;
if(c!=' ') //omitting all whitespaces
ofile.put(c);
}
ifile.close();
ofile.close();
ifile.open("copy.txt"); //reusing ifile to read from the second file
cout<<"\n\n Content of second(copied) file: "<<endl<<' ';
while(ifile.get(c))
cout<<c;
ifile.close();
system("pause");
return 0;
}