0% found this document useful (0 votes)
29 views1 page

10 File-1

The document shows how to write and read from a text file in C++. It uses ofstream and ifstream to open a file, write strings and integers to it, and then read the file back and output the contents.

Uploaded by

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

10 File-1

The document shows how to write and read from a text file in C++. It uses ofstream and ifstream to open a file, write strings and integers to it, and then read the file back and output the contents.

Uploaded by

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

#include<iostream>

#include<fstream>
#include<string>
using namespace std;
int main()
{

string str,s;
int a,b;
ofstream a_file ("example.txt");
a_file<<"This text will be inside of example.txt";
a_file<<"Welcome to DPES";
cout<<"\n Enter Name: ";
cin>>s;
a_file<<s<<" ";
cout<<"\n Enter Roll NO.: ";
cin>>a;
a_file<<a<<" ";
cout<<"\n Enter your Marks: ";
cin>>b;
a_file<<b<<"\n";
a_file.close();

ifstream b_file("example.txt");
if(b_file.is_open())
{
while(getline(b_file,str))
{
cout<<str<<"\n";
}
b_file.close();
}
cin.get();
}

You might also like