-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileHandler.cpp
More file actions
33 lines (27 loc) · 766 Bytes
/
Copy pathFileHandler.cpp
File metadata and controls
33 lines (27 loc) · 766 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
#include "FileHandler.hpp"
//constructor, initiailize the private variables
FileHandler::FileHandler(std::string file){
this->file = file;
}
void FileHandler::write(std::string content){
std::ofstream out(file);
out << content;
out.close();
}
//we can reuse content as an argument bc each fxn is isolated
DynamicList<std::string> FileHandler::splitString(std::string content, char c){
std::stringstream ss(content);
DynamicList<std::string> out;
std::string to;
while(getline(ss,to,c)){
out.push_back(to);
}
return out;
}
DynamicList<std::string> FileHandler::readLines(){
std::ifstream in(file);
std::stringstream ss;
in >> ss.rdbuf();
std::string s = ss.str();
return splitString(s,'\n');
}