file handling in c++
// basic file operations
#include <iostream>
#include <fstream>
using namespace std;
int main () {
ofstream myfile;
myfile.open ("example.txt");
myfile << "Writing this to a file.\n";
myfile.close();
return 0;
}
file handling in c++
// basic file operations
#include <iostream>
#include <fstream>
using namespace std;
int main () {
ofstream myfile;
myfile.open ("example.txt");
myfile << "Writing this to a file.\n";
myfile.close();
return 0;
}
file handling in c++
#include <iostream>
#include <fstream>
#include <cstring>
#include <process.h>
using namespace std;
int main()
{
char name[999]; //Used to store data
ofstream writeMode; //Created object of ofstream
writeMode.open("name.dat"); //Opened the file in write mode
cout<<"******** Writing into file ********"<<endl;
cout<<"Enter your name: ";
cin.getline(name, 999); //Accepts string with spaces and after spaces eg ____ ____
writeMode<<name<<endl; //Putted data inside the file
cout<<"Enter your age: ";
cin>>name;
cin.ignore(); //Wrote because number is accepted :P, may be
writeMode<<name<<endl; //Again putted data inside the file
writeMode.close(); //Closed the write mode
ifstream readMode; //Created object of ifstream
readMode.open("name.dat"); //Opened the file in read mode.
cout<<"******** Reading into file ********"<<endl;
readMode>>name;
cout<<name<<endl; //Write the data to the screen
readMode>>name; //again read the data from the file and display it
cout<<name<<endl;
readMode.close(); //Closed the read mode
system("pause");
return 0;
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us