Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
22 views2 pages

File Operations in C++ Programs

The document discusses three C++ programs: the first program creates a file, the second writes text to the file, and the third reads the text from the file. Each program is demonstrated with code snippets and expected output is shown.

Uploaded by

faseehnas
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)
22 views2 pages

File Operations in C++ Programs

The document discusses three C++ programs: the first program creates a file, the second writes text to the file, and the third reads the text from the file. Each program is demonstrated with code snippets and expected output is shown.

Uploaded by

faseehnas
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/ 2

PF Class Assignment # 04

Name : M.Faseeh Nasir


ID: 39604

Program 1:
Program to create a file.

#include <iostream>
#include <fstream>
using namespace std;
int main(){
ofstream onfile;
onfile.open("C:\\Users\\Student\\Desktop\\1stfile.txt");
onfile.close();
cout<<"File Created Successfully ;";
}

Output of Program 1

Program 2:
Program to write in a file:
#include <iostream>
#include <fstream>
using namespace std;
int main(){
ofstream onfile;
onfile.open("C:\\Users\\Student\\Desktop\\1stfile.txt");
onfile<<"Welcome to my File";
cout<<"Write Operation Performed Successfully ;";
onfile.close();

Output Of Program 2
Program 3:
Program to Read Operation:
#include<iostream>
#include<fstream>
using namespace std;
int main(){
ifstream infile;
string str;
infile.open("C:\\Users\\Student\\Desktop\\1stfile.txt");
while(getline(infile,str)){
cout<<str;

}
cout<<"Read operation performed successfully :";
infile.close();
}

You might also like