retrieving list of integers from file

i Have created file with 50000 integers of list now i need to retrieve the list can any body help me out please......... this is my piece of code for creation

list<unsigned long int>::iterator k;
ofstream thefile;
myfile.open ("output.txt");

for(k=L.begin(); k != L.end(); ++k)
{
thefile << *k << "\n";
}
thefile.close();
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <list>
#include <fstream>
#include <iterator>

std::list<int> retrieve_from( const char* path2file )
{
    std::ifstream file( "output.txt" ) ;
    std::istream_iterator<int> begin(file), end ;
    return std::list<int>( begin, end ) ;
}

int main()
{
    std::list<int> lst = retrieve_from( "output.txt" ) ;
    // use list
}
Thank you :)
Topic archived. No new replies allowed.