Using the STL LIst Container, how do I create, write,read, and store in file.

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Sep 2004
Posts: 13
Reputation: smarkles is an unknown quantity at this point 
Solved Threads: 0
smarkles smarkles is offline Offline
Newbie Poster

Using the STL LIst Container, how do I create, write,read, and store in file.

 
0
  #1
Oct 28th, 2004
This is our assignment:An STL List Container that adds at least 5 elementes, display i order, and reverse. That part I've got. I'm still doing research on the write to, store ina file and read from a file. Any help would be appreciated. Thanks Smarkles.
#include<iostream>

using namespace std;

#include<list>
#include<algorithm>

template < class T >
void printList ( const std::list< T > &listRef );

int main()
{
const int SIZE = 5;
int array[ SIZE ] = { 6,7,8,9,10};

std::list< int > values;
std::list< int > otherValues;

values.push_front( 1 );
values.push_front( 2);
values.push_back( 5 );
values.push_back( 4 );
values.push_back ( 3 );

cout << "values contains: ";
printList( values );

values.sort();

cout << "\nvalues after sorting: ";
printList(values );

values.reverse();

cout << "\nValues after reversing: ";
printList ( values );

cout << endl;

return 0;
}
template < class T >
void printList( const std::list< T > &listRef )
{
if (listRef.empty() )
cout << "List is empty";
else
{
std::ostream_iterator< T > output(cout, " " );
std::copy( listRef.begin(), listRef.end(), output );
}
}
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC