-
Notifications
You must be signed in to change notification settings - Fork 160
Expand file tree
/
Copy pathMatrixCSV.cpp
More file actions
50 lines (39 loc) · 738 Bytes
/
Copy pathMatrixCSV.cpp
File metadata and controls
50 lines (39 loc) · 738 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
48
#include "MatrixCSV.hpp"
#include <fstream>
MatrixCSV::MatrixCSV(const std::string& filename)
{
std::ifstream f(filename);
std::string line;
while (std::getline(f, line))
{
std::vector<double> row;
std::string tmp;
for (size_t i = 0; i < line.size(); ++i)
{
char c = line[i];
if (c == ';' || i + 1 == line.size())
{
row.push_back(std::stod(tmp));
tmp.clear();
}
else
{
tmp.push_back(c);
}
}
if (!row.empty())
{
m_data.push_back(row);
}
}
m_rows = m_data.size();
m_cols = m_data.front().size();
}
double MatrixCSV::getAt(size_t row, size_t col) const
{
return m_data[row][col];
}
void MatrixCSV::setAt(size_t row, size_t col, double val)
{
m_data[row][col] = val;
}