Emperor Sabi avatar

C++ read and write file program (prototype)!

learnandgrow

Published: 17 Jan 2018 › Updated: 17 Jan 2018C++ read and write file program (prototype)!

C++ read and write file program (prototype)!

Program body

#include iostream
#include string
#include fstream
using namespace std;

int main (){
string io;
cout<<"if you wanna read the file than enter read"<<endl;
cout<<"if you wanna write to file than write down in source code and enter 'write' at runtime"<<endl;
cin>>io;
if(io"read"){
ifstream file("kirito.txt");
if(!file.is_open()){
cout<<"An Error Occured"<<endl;
}else{
cout<<"Successfully opened file"<<endl;
string lines;
while(file.good()){
getline(file,lines);
cout<<lines<<endl;
}
}
}else if (io"write"){
ofstream file1("kirito.txt");
if(!file1.is_open()){
cout<<"Error in opening file"<<endl;

}else {
cout<<"Successfully opened file"<<endl;
file1 <<"Lets share our knowledge with other steemians through LEARNANDGROW"<<endl;
file1 <<"Lets do it shall we"<<endl;
cout<<"successfully written you comments"<<endl;
}
}else {
cout<<"please check your spelling and it only supports read and write commands"<<endl;
}
return 0;
}

Working of program

first of all its a prototype program.
moving on first you gotta select which catagory you wanna choose "read" or "write"
za.jpg
where as if you choose the write option as it is prototype program you gotta write here in source code.
za1.jpg
You will see that if you did it right. YOu will get that in the file.
za2.jpg
If you wanna read so simply it will appear in execution window.
za3.jpg

I hope you guys liked it stay tuned for more.

Leave C++ read and write file program (prototype)! to:

Written by

SCIENTIST, Programmer,Photographer, Entrepreneur & Steemian .

Read more #programming posts


Best Posts From Emperor Sabi

We have not curated any of learnandgrow's posts yet. But you can encourage our curation team to review posts by visiting them regularly and by referring other readers. Because we give priority to frequently read content.

More Posts From Emperor Sabi