Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions ReadWrite.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#include <iostream>

#include <fstream>

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<<endl;

}

MyReadFile.close();

return 0;

}