| | |
Using the STL LIst Container, how do I create, write,read, and store in file.
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Sep 2004
Posts: 13
Reputation:
Solved Threads: 0
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 );
}
}
#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
- write and read the text file (C#)
- STL list container and duplicates (C++)
- How read and write int values from/to a file? (C++)
- How to insert data read from text file into linked list? (Java)
- create a stl list (C++)
- write/Read into XML File Using VC++ 6.0 please help me (XML, XSLT and XPATH)
- STL list<> (C++)
- create, write & read file to/from folder (C++)
Other Threads in the C++ Forum
- Previous Thread: Multiple data being read in
- Next Thread: Time display program
| Thread Tools | Search this Thread |
api application array arrays based beginner binary bmp c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count database delete deploy developer dll download dynamiccharacterarray email encryption error file format forms fstream function functions game generator givemetehcodez graph gui homeworkhelp iamthwee ifstream image input int java lib library linker list loop looping loops map math matrix memory multiple newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference rpg simple sorting string strings temperature template text text-file tree url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets





