Skip to content

Commit 2e6c572

Browse files
author
Sumit tripathi
committed
Refactor file input/output example and update content in FileInputOutput.txt
1 parent 8785aeb commit 2e6c572

3 files changed

Lines changed: 21 additions & 4 deletions

File tree

FileInputOutput.cpp

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include<iostream>
22
#include<fstream>
3+
using namespace std;
34
/*
45
The useful classes for working with files in C++ are:
56
1. fstreambase
@@ -10,7 +11,9 @@ The useful classes for working with files in C++ are:
1011
// In order to work with files in C++, you will have to open it. Primarily, there are two ways to open a file:
1112
// 1. Using the constructor
1213
// 2. Using the member function open() of the fstream class
13-
using namespace std;
14+
15+
/*
16+
1417
int main(){
1518
// string st = "This is a text to write in a file";
1619
string st2;
@@ -27,4 +30,20 @@ int main(){
2730
getline(ik, st2); // This will get the next line from the file
2831
cout << st2 << endl; // Display the read string
2932
return 0;
33+
}
34+
35+
*/
36+
37+
int main(){
38+
ofstream out("FileInputOutput.txt");
39+
cout << "Enter your name: ";
40+
string name;
41+
cin >> name;
42+
43+
out <<"My name is "+ name;
44+
ifstream in("FileInputOutput.txt");
45+
string content;
46+
in >> content;
47+
cout << "The file of this file is " << content;
48+
return 0;
3049
}

FileInputOutput.exe

3.31 KB
Binary file not shown.

FileInputOutput.txt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
This is a text to write in a file
2-
Ram Ram Bhaiyaon
3-
Radhe Radhe
1+
My name is Sumit

0 commit comments

Comments
 (0)