how to write a map or vector into a file

hi guys,

i have a problem in my prog which is that i want to write a map or a vector into a file.

here:
map<string,string> tmp;
map<uint32_t,vector<int>> tmp2;

i want to write the map into a file in binary or something,that i can reload it in file .

could you tell me how to do this?

thanks.
You can write the data to a file as a sequence of key,value pairs.
In the simplest implementation, when you later want to read the data
from disk, the reading function should a priori know the types of the data
that have been written to disk.

In a fancier implementation, you can first write to disk the type of the keys
and the type of the values before writing out the key,value pairs. In this
case, when restoring from disk, you can have a couple of switch statements
for choosing the correct templated version of the map to be restored.
first thanks nromvcr.

now,i was writen the map data into a k-v db.
but because of many records,when reload the data is very slowly for echo item.
so i want to find a way to reload the data fast.

Rather than writing each k-v as a record into the db, you can write the records to a single binary file on disk, and store this as a blob in your db. This should speed up your writing and reading of the data. I am not a db person. You need to understand your db capabilities, and look at what will work for you.
thanks normvcr,i see.
and now,i've done.
Topic archived. No new replies allowed.