home *** CD-ROM | disk | FTP | other *** search
/ Australian Personal Computer 2000 November / APC5112K.ISO / workshop / c / fprint.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-08-27  |  844 b   |  49 lines

  1. #pragma warning( disable:4786 )
  2. #include <iostream>
  3. #include <fstream>
  4. #include <string>
  5. #include <vector>
  6.  
  7. using namespace std;
  8. typedef vector<string>strlist_t;
  9.  
  10. void readv( strlist_t &slist )
  11. {
  12.    slist.clear();
  13.    ifstream in( "input.dat" );
  14.    string s;
  15.  
  16.    if (in.fail()) {
  17.       cout << "failed to open file" << endl;
  18.       return;
  19.    }
  20.    getline(in,s);
  21.    while (in.good()) {
  22.       slist.push_back( s );
  23.       getline(in,s);
  24.    }
  25. }
  26.  
  27. void writev( ostream &os, strlist_t &slist )
  28. {
  29.    strlist_t::const_iterator i;
  30.    for (i=slist.begin();
  31.         i!=slist.end();
  32.         i++) {
  33.            os << *i << endl;
  34.    }
  35. }
  36.  
  37.  
  38. int main()
  39. {
  40.    strlist_t slist;
  41.    readv( slist );
  42.    writev( cout, slist );
  43.  
  44.    ofstream os( "Output.dat" );
  45.    if (os.is_open())
  46.       writev( os, slist );
  47.  
  48.    return 0;
  49. }