- This topic has 5 replies, 3 voices, and was last updated 17 years ago by Dody.
Viewing 6 posts - 1 through 6 (of 6 total)
-
AuthorPosts
-
February 3, 2007 at 1:05 pm #191290BattleStar-GalacticaMember
weekend get bored
#include #include #include using namespace std; int _tmain(int argc, _TCHAR* argv[]) { string filename="test.txt"; string line="hello worldrn"; fstream ofile(filename.c_str(), ios_base::out | ios_base::binary); if(!ofile.is_open()) { cout << "Cannot Open " << filename.c_str() << " for writingn"; return 0; } for(int i=0; i<5; i++) //write 4 lines to file ofile.write(line.c_str(), line.length()); ofile.close(); return 0; }
and read text file
char FileBuffer[256]; fstream ifile(filename.c_str(), ios_base::in | ios_base::binary); if(!ifile.is_open()) { cout << "Cannot Open " << filename.c_str() << " for readingn"; return 0; } while(!ifile.eof()) { ifile.getline(FileBuffer, 256); cout << FileBuffer << endl; } ifile.close();
seriously I dont use fstream in any of my programm, I use fopen,fread and fwrite. fstream for newbie to c++ 😉
February 8, 2007 at 11:00 pm #191295DodyMemberI suggest that you catch the exceptions while writing and reading (it is a must in java now days 🙂 )
and take a look about CFile at msdn ->
it is a MFC classhave fun 🙂
February 9, 2007 at 2:04 am #191294BattleStar-GalacticaMemberto make it simple the catch exception is avoid for the clarify
February 9, 2007 at 6:09 am #191293AdminAdministratorC++ is way above my little mind….im still a VB noob…lol 😀
February 9, 2007 at 6:59 am #191292BattleStar-GalacticaMemberMe too i’m vb6 noob
ninja if I were you, I learn c++ first; if you can code in c++ you can code in every programming languageFebruary 9, 2007 at 7:02 am #191291AdminAdministratorthanks for that advice man…..that sounds real good 😀
-
AuthorPosts
Related
Viewing 6 posts - 1 through 6 (of 6 total)
- You must be logged in to reply to this topic.