|
| |
Files in C++
You can save data on disk files and retrieve them at any time
- In C++ you can use file streams which behave very similarly to the
cin and cout streams.
- You must include <fstream.h>
before you use a file:
- declare an object of type fstream which will deal with your file
- associate your fstream object with an actual file on the disk
(open the file)
what can you do with an fstream object?
- open - (filename,access)
- >> - input to your variables
- << - output from your variables
- close - close the file
Example:
- #include <fstream.h>
- void main()
- {
- fstream mylist;
- mylist.open("thefile.txt",ios::out);
- mylist<<"This is it"<<endl;
- mylist.close;
- }
|