-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.cpp
More file actions
41 lines (33 loc) · 823 Bytes
/
utils.cpp
File metadata and controls
41 lines (33 loc) · 823 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
34
35
36
37
38
39
40
41
#include <iostream>
#include <vector>
#include <fstream>
#include <sstream>
#include "utils.h"
using namespace std;
vector<vector<string>> read_from_file(string file) {
ifstream myFile(file);
string lineText;
string lineTextValue;
vector<vector<string>> parts = {};
getline(myFile, lineText);
if (myFile) {
while (getline(myFile, lineText)) {
vector<string> part;
stringstream ss;
ss << lineText;
while (getline(ss, lineTextValue, ',')) {
part.push_back(lineTextValue);
}
parts.push_back(part);
}
}
myFile.close();
return parts;
}
void write_to_file(string file, string text) {
ofstream myFile(file);
if (myFile) {
myFile << text;
}
myFile.close();
}