Answer to Question #308463 in C++ for Rajat Vats

Question #308463

Copy the contents of one text file to another file, after removing all whitespaces.


1
Expert's answer
2022-03-09T06:39:37-0500
#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);
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog