Techiio-author
Started by Anik AdhikaryMay 12, 2022

Open
How to write a program in C ++ to Copy the contents of one text file to another file, after removing all whitespaces ?

3 VIEWES 0 LIKES 0 DISLIKES SHARE
0 LIKES 0 DISLIKES 3 VIEWES SHARE

I can't understand what can I do to copy one file to another.......

1 Replies

Techiio-commentatorChris Gill replied 10 days ago0 likes0 dislikes

#include <iostream>

#include <fstream>

using namespace std;

int main()

{

ifstream fs;

ofstream ft;

string str;

char sourcefile[50], destinationfile[50];

cout << "Enter Source File with Extension: ";

gets(sourcefile);

fs.open(sourcefile);

if (!fs)

{

cout << "Error in Opening Source File...!!!";

exit(1);

}

cout << "Enter Destination File with Extension: ";

gets(destinationfile);

ft.open(destinationfile);

if (!ft)

{

cout << "Error in Opening Destination File...!!!";

fs.close();

exit(2);

}

if (fs && ft)

{

while (getline(fs, str))

{

ft << str << "\n";

}

cout << "\n\n Source File Date Successfully Copied to Destination File...!!!";

}

else

{

cout << "File Cannot Open...!!!";

}

cout << "\n\n Open Destination File and Check!!!\n";

fs.close();

ft.close();

}

You must be Logged in to reply
Techiio-logo

Techiio is on the journey to build an ocean of technical knowledge, scouring the emerging stars in process and proffering them to the corporate world.

Follow us on:

Subscribe to get latest updates

You can unsubscribe anytime from getting updates from us
Developed and maintained by Wikiance
Developed and maintained by Wikiance