-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path61_b_File_IO.cpp
More file actions
33 lines (26 loc) · 770 Bytes
/
61_b_File_IO.cpp
File metadata and controls
33 lines (26 loc) · 770 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
// File I/O in C++
// Using objects and classes
#include<iostream>
#include<fstream>
using namespace std;
int main()
{
// COnnecting our file to rout stream...!!
ofstream rout("sample.txt");
// Creating a name string and filling it with the string entered by the user
cout << "Enter your name: " ;
string name;
cin >> name;
// Writing a string to the file...!!
rout << "My name is: " + name;
rout.close();
// **************************************************************
// Reading the file.
ifstream rin("sample.txt");
string content;
// rin >> content; --> Only one word will we printed
getline(rin, content);
cout << "The content of the file is : " << content;
rin.close();
return 0;
}