943,936 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 5672
  • C++ RSS
Oct 28th, 2004
0

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

Expand Post »
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 );
}
}
Similar Threads
Reputation Points: 12
Solved Threads: 0
Newbie Poster
smarkles is offline Offline
13 posts
since Sep 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Multiple data being read in
Next Thread in C++ Forum Timeline: Time display program





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC