-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBinaryWrite.cpp
More file actions
38 lines (25 loc) · 982 Bytes
/
BinaryWrite.cpp
File metadata and controls
38 lines (25 loc) · 982 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/*
* BinaryWrite.cpp
*
* Copyright 2018 OFTNAI. All rights reserved.
*
*/
// Forward declarations
// Includes
#include "BinaryWrite.h"
BinaryWrite::BinaryWrite() : fstream() {}
BinaryWrite::BinaryWrite(const char * filename) : fstream() { openFile(filename); }
BinaryWrite::BinaryWrite(const string & filename) : fstream() { openFile(filename); }
void BinaryWrite::openFile(const string & filename) { openFile(filename.c_str()); }
void BinaryWrite::openFile(const char * filename) {
this->filename = filename;
exceptions( std::ios_base::failbit | std::ios_base::badbit); //exceptions(ios_base::eofbit | ios_base::failbit | ios_base::badbit);
// Open file
try {
open(filename, std::ios_base::out | std::ios_base::binary);
} catch (fstream::failure e) {
cerr << "Unable to open file for writing: error = " << strerror(errno) << ", file = " << filename << endl;
cerr.flush();
exit(EXIT_FAILURE);
}
}