#include
#include
#include
#include
#include
#include
#include
class MyClass {
public:
MyClass() : name(""), value(0) {}
MyClass(const std::string& n, int v) : name(n), value(v) {}
template<class Archive>
void serialize(Archive & ar, const unsigned int version) {
ar & name;
ar & value;
}
void print() const {
std::cout << "Name: " << name << ", Value: " << value << std::endl;
}
private:
std::string name;
int value;
};
int main() {
std::vector<MyClass> myVector;
myVector.push_back(MyClass("Object1", 42));
myVector.push_back(MyClass("Object2", 55));
myVector.push_back(MyClass("Object3", 77));
{
std::ofstream file("vector_serialize.txt");
boost::archive::text_oarchive ar(file);
ar << myVector;
}
{
std::ifstream file("vector_serialize.txt");
boost::archive::text_iarchive ar(file);
std::vector<MyClass> loadedVector;
ar >> loadedVector;
for (const auto& obj : loadedVector) {
obj.print();
}
}
return 0;
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58