Skip to content

Instantly share code, notes, and snippets.

@shangeethsivan
Last active January 1, 2017 08:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shangeethsivan/eb1551887dce88dd81798ee1eec707da to your computer and use it in GitHub Desktop.
Save shangeethsivan/eb1551887dce88dd81798ee1eec707da to your computer and use it in GitHub Desktop.
File Operation in C++
int writedatatoFile(){
std::ofstream file("c:\\demo.dat",std::ios_base::app);
if(file.is_open()){// IF EXITS OPEN AND APPEND DATA
string data="dummy";
file<<dummy<<endl;
file.close();
return 1;
}
else{// Create a file
try{
std:"fstream nf("c:\\demo.dat",fstream::out);
if(nf.is_open()){
nf<<dummy<<endl;
nf.close();
}
else{
cout<<"ERR WHILE CREATING";
return 0;
}
}
catch(char *data){
cerr<<data;
return 0;
}
return 0;
}
/* Reading a File
std::ifstream f("c:\\train.dat");
if(f.is_open()){
while ( getline (f,line) ){
cout<<line<<endl;
}
f.close();
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment