Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 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