Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void check_file_status(char* filename) {
- std::fstream File;
- File.open(filename, std::fstream::in);
- if (File.fail()) cout << "Failed to open file for read.\n";
- File.close();
- File.open(filename, std::fstream::out | std::fstream::app);
- if (File.fail()) cout << "Failed to open file for write.\n";
- File.close();
- File.open(filename, std::fstream::in | std::fstream::out | std::fstream::app);
- char temp[2] = {0};
- if (!File.fail()) {
- File.seekg(0, std::fstream::end);
- int i = (int)File.tellg();
- cout << "Successfully opened file.\nFile size: " << i << " bytes\n";
- File.seekg(0);
- File.read(temp, 1);
- if (File.fail()) {
- cout << "Opened file for read, but ";
- if (i == 0) cout << "your file is empty.\n";
- else cout << "failed to read from file.\n";
- }
- }
- File.close();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement