This blog is about file operations. Here I only present a few functions and classes. I'll keep updating when I get new information.
Firstly, I'll introduce three objects: 1) ofstream (write, export from RAM to storage ), 2) ifstream (read, import from storage to RAM), 3) fstream (can both write and read);
1. ofstream defines an object (f). When you call the function open() and put file names in the parentneses, f would open or create(if there's no such file) the corresponding. And you can write in the file directly.
1) if you want to operate files, you must include the fstream.h head file.
2) when you define an object with ofstream, you can then operate the object with its functions such as : open(), close(), clear()
3) flags: bad() if there is error in the process, returns true.
fail() same as bad() plus return true when there is format mistake.
eof() if read to the end of the file, returns true.
good() if any of the flag above returns true, it returns false.
Useful links:
http://blog.csdn.net/kingstar158/article/details/6859379
http://blog.csdn.net/augusdi/article/details/8865378
http://blog.chinaunix.net/uid-21375345-id-3049692.html
2. ifstream defines an object that can be used to read contents from interested files to RAM.
RESULT:
By far, I just got these. This blog will be updated in the future when I encounter more contents about file operation.
update 1:
Read and Write. Function calling formats are shown below
.read(unsigned char *buf,int num);
.write(const unsigned char *buf,int num);
The read function will take ’num‘ number of charactors in the file to the variable pointed by *buf.
The write function will put 'num' number of charactors in the variable pointed by *buf into the file.
Useful links:
http://www.cplusplus.com/reference/fstream/ifstream/
http://www.prglab.com/cms/pages/c-tutorial/file-inputoutput.php
http://blog.csdn.net/luo809976897/article/details/51442070