Writing values in a list to a textfile

Hi, is it possible to write values that are stored in a list to a text file?
Yes, it is.
may i know how it can be done?
I tried searching google but all i found was the solutions to write vector data to a text file
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' ; } ) ;
}


If the type of the sequence container is made a template parameter, the same code will work for any standard library compatible sequence container.
Thanks alot man.
I have also figured out a way. I will put it here if anyone needs it.

1
2
3
4
5
6
7
8
9
10
list<list-name>::iterator itr
ofstream output("output.txt");
	for(itr=<list-name>.begin();itr != <list-name>.end();++itr)
	{
	  
	   
	   output<<itr->GetTopic();
	   output<<itr -> GetStartTime();
	   output<<itr -> GetDuration();
	}
Topic archived. No new replies allowed.