#include <vector>
#include <iostream>
#include <iterator>
#include <fstream>
struct Node
{
int x;
int y;
Node() : x(0), y(0) {}
Node(int x, int y) : x(x), y(y) {}
friend std::ostream& operator<<(std::ostream& os, const Node& node)
{
os << node.x << " " << node.y << " ";
return os;
}
friend std::istream& operator>>(std::istream& is, Node& node)
{
is >> node.x >> node.y;
return is;
}
};
class Way
{
private:
std::vector<Node> path;
public:
Way(){}
Way(const std::vector<Node>& path) : path(path) {}
Way(const Way& otherWay) : path(otherWay.path) {}
// в файл пишем количество элементов в path и сам path
friend std::fstream& operator<<(std::fstream& os, const Way& way)
{
os << way.path.size() << " ";
std::copy(way.path.begin(), way.path.end(), std::ostream_iterator<Node>(os, " "));
os << std::endl;
return os;
}
friend std::fstream& operator>>(std::fstream& is, Way& way)
{
size_t size = 0;
is >> size;
way.path.resize(size);
std::copy_n(std::istream_iterator<Node>(is), size, way.path.begin());
return is;
}
// на экран выводим только содержимое path
friend std::ostream& operator<<(std::ostream& os, const Way& way)
{
std::copy(way.path.begin(), way.path.end(), std::ostream_iterator<Node>(os, " "));
os << std::endl;
return os;
}
};
int main()
{
std::vector<Node> path0{ Node(3,2), Node(2,4), Node(4,5) };
std::vector<Node> path1{ Node(1,4), Node(4,3), Node(3,2) };
Way way0(path0);
Way way1(path1);
std::fstream ways;
ways.open("1.txt", std::ios_base::out | std::ios_base::trunc);
ways << way0 << way1;
ways.close();
Way way0r;
Way way1r;
ways.open("1.txt", std::ios_base::in);
ways >> way0r >> way1r;
ways.close();
std::cout << way0r << way1r;
return 0;
}