0% found this document useful (0 votes)
5 views5 pages

Experiment No-11

The document contains C++ code snippets for basic file operations including creating, writing, reading, copying, and deleting files. Each section demonstrates how to handle files using the fstream library in C++. The operations are performed on a file located at 'D:\file.txt' and its copy 'D:\file_New.txt'.

Uploaded by

gmranuj
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views5 pages

Experiment No-11

The document contains C++ code snippets for basic file operations including creating, writing, reading, copying, and deleting files. Each section demonstrates how to handle files using the fstream library in C++. The operations are performed on a file located at 'D:\file.txt' and its copy 'D:\file_New.txt'.

Uploaded by

gmranuj
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

\\Create File

#include<iostream>

#include<fstream>

using namespace std;

int main()

ofstream onfile;

onfile.open("D:\\file.txt");

cout<<"file create successfully";

onfile.close();

return 0;

}
// Write File

#include<iostream>

#include<fstream>

using namespace std;

int main()

ofstream onfile;

onfile.open("D:\\file.txt");

onfile<<"Thank You So Much";

cout<<"Data has been written successfully";

onfile.close();

return 0;

}
// Read File

#include<iostream>

#include<fstream>

using namespace std;

int main()

ifstream infile;

string str;

infile.open("D:\\file.txt");

while(getline(infile,str))

cout<<str;

infile.close();

return 0;

}
// Copy File

#include<iostream>

#include<fstream>

using namespace std;

int main()

ifstream infile;

ofstream onfile;

char str;

infile.open("D:\\file.txt");

onfile.open("D:\\file_New.txt");

while(infile.get(str))

onfile.put(str);

cout<<"Copied";

infile.close();

onfile.close();

return 0;

}
// Delete File

#include<iostream>

#include<fstream>

using namespace std;

int main()

int value=remove("D:\\file_New.txt");

if (value==0)

cout<<"file Deleted";

else

{cout<<"file not deleted";

return 0;

You might also like