From b7797a05eb3d25216ca285a1a857d1a0070f629f Mon Sep 17 00:00:00 2001 From: Nayan Jain <71127472+NayanJain7@users.noreply.github.com> Date: Sat, 3 Oct 2020 09:00:22 +0530 Subject: [PATCH] Create ReadWrite.cpp --- ReadWrite.cpp | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 ReadWrite.cpp diff --git a/ReadWrite.cpp b/ReadWrite.cpp new file mode 100644 index 0000000..6f2d44f --- /dev/null +++ b/ReadWrite.cpp @@ -0,0 +1,49 @@ +#include + +#include + +using namespace std; + +int main() { + + ofstream MyFile("sample.txt"); + + cout<<"Writing into a file\n"; + + string data; + + cout<<"Enter your name : \n"; + + cin>>data; + + + + MyFile << data << endl; + + cout<<"Enter your age : "; + + cin>>data; + + MyFile << data << endl; + + + + MyFile.close(); + + string myText; + +ifstream MyReadFile("sample.txt"); + +cout<<"Reading from a file\n"; + +while (getline (MyReadFile, myText)) { + + cout << myText<