-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMatrixFileIO.h
More file actions
37 lines (32 loc) · 833 Bytes
/
MatrixFileIO.h
File metadata and controls
37 lines (32 loc) · 833 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
//
// Created by raf on 5/20/20.
//
#ifndef MATRIXPROJECT_MATRIXFILEIO_H
#define MATRIXPROJECT_MATRIXFILEIO_H
#include <vector>
#include <string>
#include <fstream>
template <class T>
class MatrixFileIO {
public:
std::vector<std::vector<T>> readMatrixFile(std::string fileName);
};
template <class T>
std::vector<std::vector<T>> MatrixFileIO<T>::readMatrixFile(std::string fileName){
std::string line;
std::ifstream infile(fileName);
std::vector<std::vector<T>> data;
while(std::getline(infile, line)){
std::vector<T> r;
for(char &d : line){
if(d != ','){
double x = (double)d;
T y = (T)x;
r.push_back(x);
}
}
data.push_back(r);
return data;
}
}
#endif //MATRIXPROJECT_MATRIXFILEIO_H