-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patht62_open_and_eof_fn.cpp
More file actions
38 lines (30 loc) · 880 Bytes
/
Copy patht62_open_and_eof_fn.cpp
File metadata and controls
38 lines (30 loc) · 880 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
28
29
30
31
32
33
34
35
36
37
38
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
// declaring an object of the type ofstream
ofstream out;
//connecting the object out to the text file using the member function open()
out.open("sample60.txt");
//writing to the file
out <<"This is me\n";
out <<"This is also me";
//closing the file connection
out.close();
// declaring an object of the type ifstream
ifstream in;
//declaring string variable st
string st;
//opening the text file into in
in.open("sample60.txt");
// giving output the string lines by storing in st until the file reaches the end of it
while (in.eof()==0)
{
// using getline to fill the whole line in st
getline(in,st);
cout<<st<<endl;
}
return 0;
}