I have an std::map.
I would like to know if I can write it to a file (and also read it from a file) in like 1 line using fwrite, or if I need to write/read each value separately.
I was hoping that since is nothing special, this might be possible.
I have an std::map.
I would like to know if I can write it to a file (and also read it from a file) in like 1 line using fwrite, or if I need to write/read each value separately.
I was hoping that since is nothing special, this might be possible.
use
boost::serialization
for serialize in one line. Header for it:Code example
Output:
for file simply use
std::ifstream/std::ofstream
instead ofstd::stringstream
and may bebinary_archive
, instead oftext_archive
.There isn't a one-liner to serialize a map. You would need to write each key/value pair individually. This really isn't much more complicated than a for loop, though.
Using boost, there might be a way, but I'm not familiar with the exact APIs.