C++ Serializing a std::map to a file

后端 未结 6 801
星月不相逢
星月不相逢 2020-12-31 07:07

I have a C++ STL map, which is a map of int and customType. The customType is a struct, which has string and a list of string, How can i serialize this to a file.

sa

6条回答
  •  醉酒成梦
    2020-12-31 07:30

    C++ doesn't have reflection capabilities like Java and others, so there's no 'automatic' way of doing that. You'll have to do all the work yourself: open the file, output each element in a loop, and close the file. Also there's no standard format for the file, you'd need to define one that meets your needs. Of course, there are libraries out there to help in this, but they aren't part of the language. Take a look at this question:

    Is it possible to automatically serialize a C++ object?

    Also take a look at: http://s11n.net/

提交回复
热议问题