-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLAB9.cpp
More file actions
27 lines (27 loc) · 709 Bytes
/
Copy pathLAB9.cpp
File metadata and controls
27 lines (27 loc) · 709 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
/*Develop a C++ program to create a text file, check file created or not, if created it will write some
text into the file and then read the text from the file.*/
#include <fstream>
#include <iostream>
#include<stdlib.h>
using namespace std;
int main()
{
fstream fh;
char str[200];
fh.open("File_1.txt", ios::out);
if( !fh.is_open() )
{
cout << "File did not open!";
exit(1);
}
fh<< "This is a sample text File. " << endl;
fh<< "This is the second line of the file. " << endl;
fh.close();
fh.open("File_1.txt",ios::in);
fh.getline(str,90,'\n');
cout<<str<<endl;
fh.getline(str,90,'\n');
cout<<str<<endl;
fh.close();
return 0;
}