<p>I need to write the content of a map (key is ID of int, value is of self-defined struct) into a file, and load it from the file later on. Can I do it in MFC with CArchive?</p>

<p>Thank you!</p>

I don't know much about MFC, but your problem is rather trivially solved using
Boost.Serialization
```
```
struct MapData {
     int m_int;
     std::string m_str;

  private: 
    friend class boost::serialization::access; 

    template<class Archive> 
    void serialize(Archive &ar, const unsigned int version) 
    { 
        ar & m_int; 
        ar & m_str; 
    } 
};

std::map< int, MapData > theData;

template<class Archive>
void serialize(Archive & ar, std::map< int, MapData > & data, const unsigned int version)
{
    ar & data;
}
```
```
And then later were you want to do the real archiving:
```
```
std::ofstream ofs("filename"); 
boost::archive::binary_oarchive oa(ofs); 
oa << theData;
```
```
That's it.
(disclaimer: code simply typed in this box, not tested at all, typo's were intended ;)