Advertisement
CVSoft

Untitled

Apr 26th, 2015
257
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. void check_file_status(char* filename) {
  2.     std::fstream File;
  3.     File.open(filename, std::fstream::in);
  4.     if (File.fail()) cout << "Failed to open file for read.\n";
  5.     File.close();
  6.     File.open(filename, std::fstream::out | std::fstream::app);
  7.     if (File.fail()) cout << "Failed to open file for write.\n";
  8.     File.close();
  9.     File.open(filename, std::fstream::in | std::fstream::out | std::fstream::app);
  10.     char temp[2] = {0};
  11.     if (!File.fail()) {
  12.         File.seekg(0, std::fstream::end);
  13.         int i = (int)File.tellg();
  14.         cout << "Successfully opened file.\nFile size: " << i << " bytes\n";
  15.         File.seekg(0);
  16.         File.read(temp, 1);
  17.         if (File.fail()) {
  18.             cout << "Opened file for read, but ";
  19.             if (i == 0) cout << "your file is empty.\n";
  20.             else cout << "failed to read from file.\n";
  21.         }
  22.     }
  23.     File.close();
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement