User Tools

Site Tools


cplusplus:file_processing_examples

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Next revisionBoth sides next revision
cplusplus:file_processing_examples [2016/09/27 02:13] – [Filenames must be c_str in C++98 and earlier] mithatcplusplus:file_processing_examples [2017/02/08 20:46] – [Filenames must be c_str in pre-C++11] mithat
Line 42: Line 42:
  
     if (!outfile)     if (!outfile)
-        cout << "Error opening file." << endl; 
-    else 
     {     {
-        cout << "Writing to the file ... ";+        cout << "Error opening file." << endl; 
 +        return 1 // exit program with an error code 
 +    }
  
-        outfile << "KCMP\t" << 89.3 << endl; +    cout << "Writing to the file ... ";
-        outfile << "KNOW\t" << 91.1 << endl; +
-        outfile << "KSJN\t" << 99.5 << endl; +
-        outfile.close();    // close the file!+
  
-        cout << "Done!" << endl; +    outfile << "KCMP\t" << 89.3 << endl; 
-    }+    outfile << "KNOW\t" << 91.1 << endl; 
 +    outfile << "KSJN\t" << 99.5 << endl; 
 +    outfile.close();    // close the file! 
 + 
 +    cout << "Done!" << endl;
  
     return 0;     return 0;
Line 81: Line 82:
  
     if (!outfile)     if (!outfile)
-        cout << "Error opening file." << endl; 
-    else 
     {     {
-        cout << "Writing to the file ... ";+        cout << "Error opening file." << endl; 
 +        return 1 // exit program with an error code 
 +    }
  
-        outfile << "KCMP\t" << 89.3 << endl; +    cout << "Writing to the file ... ";
-        outfile << "KNOW\t" << 91.1 << endl; +
-        outfile << "KSJN\t" << 99.5 << endl; +
-        outfile.close();    // close the file!+
  
-        cout << "Done!" << endl; +    outfile << "KCMP\t" << 89.3 << endl; 
-    }+    outfile << "KNOW\t" << 91.1 << endl; 
 +    outfile << "KSJN\t" << 99.5 << endl; 
 +    outfile.close();    // close the file! 
 + 
 +    cout << "Done!" << endl;
  
     return 0;     return 0;
cplusplus/file_processing_examples.txt · Last modified: 2019/02/11 19:17 by mithat

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki