Copy the contents of one text file to another file, after removing all whitespaces.
#include<conio.h>
#include<stdio.h>
#include<stdlib.h>
#include <iostream>
using namespace std;
//Copy the contents of one text file to another file, after removing all whitespaces.
main(void)
{
ifstream infile,outfile;
char x,y;
string f_1 = "H:\\Text_1.txt";
string f_2 = "H:\\Text_2.txt";
infile.open(f_1.c_str());
outfile.open(f_2.c_str());
if (!infile)
{
cout << "Unable to open file: "<<f_1;
exit(1); // terminate with error
}
else
{
cout<<"\nContents of File_1.txt: ";
while(infile >> x)
{
if(x!=0x20) outfile<<x;}
}
infile.close();
outfile.close();
}
return(0);
}
Comments
Leave a comment