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"
where as if you choose the write option as it is prototype program you gotta write here in source code.
You will see that if you did it right. YOu will get that in the file.
If you wanna read so simply it will appear in execution window.
I hope you guys liked it stay tuned for more.
Leave C++ read and write file program (prototype)! to:
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
- Thursday freewrite__ Prompt: cityscape
- ZapFic Monday - Prompt: engagement in 240 character or less
- Poser Pro 11 - Discover the Art of the Human Form with Poser
- YELLOW PAGES SPIDER - GET THOUSANDS OF LEADS ON DEMAND
- MindGenius Business - Creating complex business idea maps, strategies,plans & more
- Quickbooks Pro - software for managing businesses effectively and efficiently
- Autodesk Revit MEP - Best for designing 2D structural and 3D model of a building
- eDrawings Professional - The Easiest Way to Share 3D Data Across CAD Environments
- GiftedMotion - GiftedMotion is a free and easy & open source GIF animator
- Blumentals WeBuilder - fast, intelligent & all in one code editor for web developer