-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCSVFile.cpp
More file actions
47 lines (47 loc) · 730 Bytes
/
CSVFile.cpp
File metadata and controls
47 lines (47 loc) · 730 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
42
43
44
45
46
47
#include "CSVFile.h"
CSVFile::CSVFile(string path)
{
Path = path;
Stream.open(Path);
}
CSVFile::~CSVFile()
{
Stream.close();
}
vector<string> CSVFile::ParseLine(string line)
{
vector<string> strings;
string s;
for (int i = 0; i < line.size(); i++)
{
s += line[i];
if (line[i] == ',')
{
s.pop_back();
strings.push_back(s);
s = "";
}
}
strings.push_back(s);
return strings;
}
vector<string> CSVFile::Load()
{
vector<string> result;
Stream.seekg(0);
string line;
while (getline(Stream, line))
{
if(!line.empty())
result.push_back(line);
}
return result;
}
void CSVFile::Save(vector<string> Lines)
{
Stream.seekp(0);
for (int i = 0; i < Lines.size(); i++)
{
Stream << Lines[i] << endl;
}
}