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

  1. #include <iostream>
  2. #include <fstream>
  3.  
  4. using namespace std;
  5.  
  6. void save1()
  7. {
  8.    ofstream of;
  9.    
  10.    of.open( "Hello1.dat" );
  11.  
  12.    if (!of.is_open()) {
  13.       cout << "failed to open file" << endl;
  14.       return;
  15.    }
  16.    of << "Hello World!" << endl;
  17.    if (of.fail()) 
  18.       cout << "failed to write to file" << endl;
  19.    of.close();
  20. }
  21.  
  22. void save2()
  23. {
  24.    ofstream of( "Hello2.dat" );
  25.  
  26.    if (!of) {
  27.       cout << "failed to open file" << endl;
  28.       return;
  29.    }
  30.    of << "Hello World!" << endl;
  31.    if (!of) 
  32.       cout << "failed to write to file" << endl;
  33. }
  34.  
  35.  
  36.  
  37. int main()
  38. {
  39.    save1();
  40.    save2();
  41.    return 0;
  42. }