Last active
January 1, 2017 08:51
-
-
Save shangeethsivan/eb1551887dce88dd81798ee1eec707da to your computer and use it in GitHub Desktop.
File Operation in C++
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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