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
|
#include <list>
#include <fstream>
#include <iterator>
#include <algorithm>
template< typename T, typename A >
void write_to_file_1( const std::list<T,A>& seq, const char* path2file )
{
std::ofstream file(path2file) ;
for( const auto& v : seq ) file << v << '\n' ;
}
template< typename T, typename A >
void write_to_file_2( const std::list<T,A>& seq, const char* path2file )
{
std::ofstream file(path2file) ;
for( auto iterator = seq.begin() ; iterator != seq.end() ; ++iterator )
file << *iterator << '\n' ;
}
template< typename T, typename A >
void write_to_file_3( const std::list<T,A>& seq, const char* path2file )
{
std::ofstream file(path2file) ;
std::copy( seq.begin(), seq.end(), std::ostream_iterator<T>( file, "\n" ) ) ;
}
template< typename T, typename A >
void write_to_file_4( const std::list<T,A>& seq, const char* path2file )
{
std::ofstream file(path2file) ;
std::for_each( seq.begin(), seq.end(), [&file] ( const T& v ) { file << v << '\n' ; } ) ;
}
|