954,500 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

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

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

using namespace std;

#include
#include

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 );
}
}

smarkles
Newbie Poster
13 posts since Sep 2004
Reputation Points: 12
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You