-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileInputOutput.cpp
More file actions
123 lines (101 loc) · 2.43 KB
/
FileInputOutput.cpp
File metadata and controls
123 lines (101 loc) · 2.43 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#include "FileInputOutput.h"
FileInputOutput::FileInputOutput()
{
}
FileInputOutput::~FileInputOutput()
{
}
// main functions
void FileInputOutput::__WriteToFile( std::string filePath,std::string contentString,bool append )
{
std::ofstream fileStream( filePath,( append ) ? std::ios::app : std::ios::trunc );
if( fileStream.is_open() )
{
fileStream << contentString;
fileStream.close();
}
}
std::string FileInputOutput::__ReadFromFile( std::string filePath )
{
std::stringstream content;
std::string curLine;
std::ifstream fileStream( filePath );
if( fileStream.is_open() )
{
while( std::getline( fileStream,curLine ) )
{
content << curLine << '\n';
}
fileStream.close();
}
return content.str();
}
std::vector<std::string> FileInputOutput::__ReadFromFileToVector( std::string filePath )
{
std::vector<std::string> content;
std::string curLine;
std::ifstream fileStream( filePath );
if( fileStream.is_open() )
{
while( std::getline( fileStream,curLine ) )
{
content.push_back( curLine );
}
fileStream.close();
}
return content;
}
std::wstring FileInputOutput::__ReadFromFile_WStr( std::string filePath )
{
Widen<wchar_t> to_wstring;
std::stringstream content;
std::string curLine;
std::ifstream fileStream( filePath );
if( fileStream.is_open() )
{
while( std::getline( fileStream,curLine ) )
{
content << curLine << '\n';
}
fileStream.close();
}
return to_wstring( content.str() );
}
std::vector<std::wstring> FileInputOutput::__ReadFromFileToVector_WStr( std::string filePath )
{
Widen<wchar_t> to_wstring;
std::vector<std::wstring> content;
std::string curLine;
std::ifstream fileStream( filePath );
if( fileStream.is_open() )
{
while( std::getline( fileStream,curLine ) )
{
content.push_back( to_wstring( curLine ) );
}
fileStream.close();
}
return content;
}
// utility functions:
std::string FileInputOutput::__VectorToString( std::vector<std::string> stringVector )
{
std::ostringstream oss;
if( !stringVector.empty() )
{
std::copy( stringVector.begin(),stringVector.end() - 1,
std::ostream_iterator<std::string>( oss ) );
}
return oss.str();
}
std::vector<std::string> FileInputOutput::__StringsToVector( std::string strings,char delimiter )
{
std::vector<std::string> retVec;
std::stringstream ss( strings );
std::string curLine;
while( getline( ss,curLine,delimiter ) )
{
retVec.push_back( curLine );
}
return retVec;
}