-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfileWriter.hpp
62 lines (52 loc) · 1.22 KB
/
fileWriter.hpp
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*
File: fileWriter.hpp
Description: C++ class to easily write file
Author: Axel BORJA
Copyright: (C) Axel BORJA
mail: [email protected]
*/
#ifndef _FILEWRITER_H_
#define _FILEWRITER_H_
#include <fstream>
#include <string>
//
// File writing class
// Provide file write functions
//
class cFileWriter
{
public:
// Constructor
// Open file here
cFileWriter(const char * iFilename)
{
_outputFileStream.open(iFilename);
}
// Destructor
// Close file here (guarantee file closing)
~cFileWriter()
{
_outputFileStream.close();
}
// Check is file stream is open
inline bool is_open() const
{
return _outputFileStream.is_open();
}
// Put a new line of data
// Return false if something went wrong
inline bool putLine(const std::string& iLine)
{
_outputFileStream.write(iLine.c_str(), iLine.size());
_outputFileStream.put('\n');
return _outputFileStream.good();
}
// Move output file stream to position 0 (begin of the file)
inline void goToBeginningOfFile()
{
_outputFileStream.seekp(0);
}
private:
std::ofstream _outputFileStream;
};
#endif // _FILEWRITER_H_