Persistent data storage options

This is one of those questions that solicit contextual information. In particular, I'm interested in learning the different ways that a C/C++ program can store data that can be retrieved once it restarts after exiting.

With the exception of Streams (those which enable file-read/edit/output), language features and libraries of C and C++ allow programmers to manipulate data stored in a computer system's RAM. This is true for C/C++ variants used to program microcontrollers as well since they too have RAM.

But RAM is volatile (and relatively limited in capacity but this is subject for another thread).

If you were to create a program that lets users enter a series of name-address pair (as in the classic "address book" problem), and that program saves the pair on the "heap" (dynamically alloc), it's as good as gone once that program exits. Once "runtime" is over, the memory is freed for other applications to use.

C/C++ libraries provide the stream class to allow programmers to write data out to a file as plaintext, which is stored in non-volatile memory. AFAIK, you can format the data to a standard format (XML or CSV or define your own plaintext format) so that you can use parsers that already exist (or if you've defined your own, write a parser) to retrieve formatted data.

The stream library also lets you open files in "binary mode" but I don't know what this means or how to use it. I suspect that it lets programmers write to a file at the byte-level and that this is a mechanism that enables programmers to define their own file format.

Questions

1. I only know about XML, CSV. What other plaintext formats exist for which there are parsers and documentation?

2. Are there non-plaintext, binary-based file formats which you can use C/C++ to output data into (for which parsers exist, documentation is available)?




C++ is a flexible and modern programming language, you are only limited by your ability to understand and parse a file's structure. I frequently use JSON or YAML when files need to be human readable, and SQLite if not.
Topic archived. No new replies allowed.