Trad
New Member
Posts: 1,122
|
Post by Trad on May 22, 2003 13:07:26 GMT -5
Im not a file i/o wiz (yet) but i know a fair deal about it and i will try and explain the simple concepts. ok, nearly all the time you will need this header file #include <fstream.h> thats for In and Out. you declare what you want in the main function ofstream = to read and write ifstream = In stream, reading ostream = Out strem, writing, so say i want to write "Hello world" to a file #include <fstream.h> int main() { ofstream file("C:\\Folder\\File"); if (file.is_open()) { file << "Hello World" << endl; } file.close(); return 0; } say we want to read from a file. #include <fstream.h> #include <iostream.h> int main() { ifstream readfile("C:\\Folder\\File"); char buffer[256]; if (readfile.is_open()) { while (!readfile.eof()) { readfile.getline(buffer,256); cout << buffer << endl; } } return 0; } thats a very simple, way, there is a LOT more about File I/O that i left out, like opening file modes etc. If you request more, i will write in more detail.
|
|