-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathfileio.cpp
More file actions
43 lines (33 loc) · 1.01 KB
/
Copy pathfileio.cpp
File metadata and controls
43 lines (33 loc) · 1.01 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
#include "fileio.h"
#include <sstream>
namespace fileio {
std::vector<std::string> file_to_vector(const std::string & file) {
std::ifstream text(file);
std::vector<std::string> out;
if (text.is_open()) {
std::istream_iterator<std::string> eos;
std::istream_iterator<std::string> iter(text);
while (iter != eos) {
out.push_back(*iter);
++iter;
}
}
return out;
}
std::vector<std::vector<std::string>> csv_to_tokens(const std::vector<std::string> & csv) {
std::vector<std::vector<std::string>> result;
for (std::string s : csv) {
result.push_back(split_string(s, ','));
}
return result;
}
std::vector<std::string> split_string(std::string& to_split, const char& delim) {
std::vector<std::string> result;
std::istringstream stream(to_split);
std::string token;
while (std::getline(stream, token, delim)) {
result.push_back(token);
}
return result;
}
}