-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathFileOperations.cpp
executable file
·55 lines (47 loc) · 1.95 KB
/
FileOperations.cpp
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
#include "FileOperations.h"
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
bool FileOperations::OpenOutputFile( std::ofstream& fileout, const std::string& sFileName ) {
if (fileout.is_open( )) return true;
else if (!fileout) {
std::cout << "Did not create the file" << std::endl;
}
else {
fileout.open( sFileName.c_str( ), std::ios::out | std::ios::app | std::ios::ate );
int count = 0;
// do our best to open the output file
while (count < 1000 && !fileout.is_open( )) {
++count;
}
}
return fileout.is_open( );
}
void FileOperations::WriteFile( std::ofstream& fileout, const std::string& svg ) {
fileout << svg << std::endl;
}
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
void FileOperations::Write( const std::string& sFileName, const std::string& text ) {
std::ofstream fileout;
if (OpenOutputFile( fileout, sFileName.c_str( ) ) )
WriteFile( fileout, text );
fileout.close( );
}
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
void FileOperations::Write( const std::string& sFileName, const std::vector<std::string>& text ) {
std::ofstream fileout;
if (OpenOutputFile( fileout, sFileName.c_str( ) )) {
std::vector<std::string>::const_iterator it;
for (it = text.begin( ); it != text.end( ); ++it)
WriteFile( fileout, *it );
fileout.close( );
}
}
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
void FileOperations::Write( const std::string& sFileName, const std::list<std::string>& text ) {
std::ofstream fileout;
if (OpenOutputFile( fileout, sFileName.c_str( ) )) {
std::list<std::string>::const_iterator it;
for (it = text.begin( ); it != text.end( ); ++it)
WriteFile( fileout, *it );
fileout.close( );
}
}