Check an archive whether it is a binary/text/xml

  archive, boost, boost-serialization, c++

I created an output text_archive and I restored it using binary archive and obviously, got some issues.
Can I know somehow the kind of archive, so that I could possibly use the appropriate code for binary/xml/text archive.

class Info
{
private:
  // Allow serialization to access non-public data members.
  friend class boost::serialization::access;

  // Serialize the std::vector member of Info
  template<class Archive>
  void serialize(Archive & ar, const unsigned int version)
  {
    ar & filenames;
  }

  std::vector<std::string> filenames;


};


int main(int argc, char** argv)
{
  Info info;
  
   // Save filename data contained in Info object
  {
    // Create an output archive
    std::ofstream ofs( "store.dat" );
    **boost::archive::text_oarchive ar(ofs);**
    ar & info;
  }

  // Restore from saved data and print to verify contents
  Info restored_info;
  {
    // Create and input archive
    std::ifstream ifs( "store.dat" );
    **boost::archive::binary_iarchive ar(ifs);**
    // Load the data
    ar & restored_info;
  }
  return 0;
}

Source: Windows Questions C++

LEAVE A COMMENT