Why I can not input from archive std::map ?
line: inputArchive >> inputContainer causes compile error:
Thanks
Adam
#include <string>
#include <iostream>
#include <fstream>
#include <sstream>
#include <map>
#include
compiled for me on msvc 7.1 Robert Ramey Adam Szeliga wrote:
Why I can not input from archive std::map ?
line: inputArchive >> inputContainer causes compile error:
Thanks Adam
#include <string> #include <iostream> #include <fstream> #include <sstream> #include <map> #include
#include #include #include #include #include #include #include #include #include #include class A { public: A() {}; A(std::string const & s): s(s) { }
virtual ~A() {};
private: std::string s;
friend std::ostream & operator<<(std::ostream & os, A const & a);
friend class boost::serialization::access; template<class Archive> void serialize(Archive & archive, unsigned int const version) { archive & s; } };
std::ostream & operator<<(std::ostream & os, A const & a) { return os << a.s; }
typedef std::map
Container; BOOST_CLASS_TRACKING(Container, boost::serialization::track_never);
std::ostream & operator<<(std::ostream & os, Container const & container) { Container::const_iterator end = container.end(); for (Container::const_iterator i = container.begin(); i != end; ++i) { os << "(" << i->first << "," << *i->second << ")" << std::endl; } return os; }
int _tmain(int argc, _TCHAR* argv[]) { std::cout << "serialization map test starts" << std::endl;
Container outputContainer;
outputContainer.insert(std::make_pair(1, new A("one"))); outputContainer.insert(std::make_pair(4, new A("four"))); outputContainer.insert(std::make_pair(2, new A("two")));
std::cout << outputContainer << std::endl;
{ std::wofstream outputFile("data.txt"); boost::archive::text_woarchive outputArchive(outputFile);
outputArchive << outputContainer; }
std::cout << "---------------------------" << std::endl;
Container inputContainer; { std::wifstream inputFile("data.txt"); boost::archive::text_wiarchive inputArchive(inputFile);
inputArchive >> inputContainer; // this line causes compile error }
std::cout << inputContainer << std::endl;
std::cout << "serialization map test ends" << std::endl;
return 0; }
participants (2)
-
Adam Szeliga
-
Robert Ramey