You are on page 1of 4

NATIONAL UNIVERSITY OF TECNOLOGY ISLAMABAD

FILE HANDLING PRACTICE

NAME ID DEPARTMENT
ARSLAN AFZAL F18602037 MECHANICAL

STORAGE OT TEXT WITH FILE NAME


#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int main()
{
ofstream outfile;
outfile.open("op.txt")
outfile << "welcome to you Arslan"<< endl;
outfile << "you learned good the concept of file handling";
outfile.close();

OUTPUT FILE
#include <iostream>

#include <string>

#include <fstream>

using namespace std;

int main()

ofstream outfile;

string name;

cout << "Enter the file name to be created:";

create:"";

getline(cin, name);

outfile.open(name + ".txt");

outfile << " welcome to you Arslan" << endl;

outfile << "you learned good the concept of file handling";

outfile.close();

}
READ INPUT FILE

#include <iostream>

#include <string>

#include <fstream>

using namespace std;

int main()

ifstream inputfile;

ofstream outfile;

string name;

cout << "Enter the file name to be created:";


getline(cin, name);

outfile.open(name + ".txt");

/*/outfile << " welcome to you Arslan" << endl;

outfile << "you learned good the concept of file handling";*/

for(int i=1 ;i<=10 ;i++)

inputfile >> name;

cout << "Read data:" << i << name;

inputfile.close();

You might also like