What is the use of reading and writing binary files and sequential reading and writing in CUniverse +?
This article mainly introduces the use of binary files and sequential reading and writing in CAccord +. The article is very detailed and has a certain reference value. Interested friends must finish reading it!
Overview
Unlike text files, binary files can be used for any type of file (including text files).
Binary vs ASCII
For numerical data, the ASCII form is different from the binary form. ASCII files are intuitive and easy to read, but they generally take up more storage space and take time to convert. Binary file is the internal form of computer, which saves space and does not need to be converted, but can not be displayed intuitively.
For character information, it is stored in ASCII code in memory, whether output by ASCII file or binary file, the form is the same.
Binary write # include # include using namespace std;int main () {int x = 12345; ofstream outfile ("binary.txt", ios::binary); outfile.write ((char*) & x, 2); / / write outfile.close (); / / release return 0;}
Output result:
ASCII write
Write int x = 12345 to the file.
# include # include using namespace std;int main () {int x = 12345; ofstream outfile ("ASCII.txt"); outfile