1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|
int main()
{
constexpr const char* path2file = "contracts.txt" ;
{
std::vector<contract> seq = { { {1,2,3,4,5,6,7}, 25, "hello world" },
{ {}, 3, "hello again" },
{ {6,22,17}, 9, "bye" } } ;
// write out the contracts in the sequence to a file
std::ofstream fout( path2file ) ;
for( const auto& c : seq ) fout << c << '\n' ;
}
{
// read the contracts in the file into the sequence of contracts
std::ifstream fin( path2file ) ;
std::vector<contract> seq( ( std::istream_iterator<contract>(fin) ),
( std::istream_iterator<contract>() ) ) ;
// just to verify that things have been read back correctly
for( const auto& c : seq ) std::cout << c << "\n--------\n\n" ;
}
}
|