Advertisement
Felanpro

Tips for File Handling

May 2nd, 2016
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.39 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.     ofstream file1("wtfm8.txt");
  9.  
  10.     if(file1.is_open()) //If file1 is ascossiated with a file in this case wtm8.txt
  11.     {
  12.         cout << "File is open." << endl;
  13.     }
  14.     else
  15.     {
  16.         cout << "File is not open." << endl;
  17.     }
  18.  
  19.     file1 << "hello nerd!\n";
  20.  
  21.     file1.close();
  22.  
  23.     return 0;
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement