-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmatrix.cpp
More file actions
40 lines (36 loc) · 966 Bytes
/
matrix.cpp
File metadata and controls
40 lines (36 loc) · 966 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
#include <fstream>
#include <iostream>
#include <string>
#include <sstream>
#include <cstdint>
#include <cstdlib>
#include "matrix.h"
template <typename T>
void matrix<T>::getMatrix(const char *fname) {
std::ifstream fin(fname);
for (size_t i=0;i<size;++i) {
std::string row;
std::getline(fin,row);
std::istringstream is(row);
for (size_t j = 0;j < size; ++j) {
char buf[8];
is >> buf;
//is >> data[i][j];
if (buf[0]== '*') data[i][j]=INT32_MAX>>1;
else data[i][j]= std::atoi(buf);
}
}
fin.close();
}
template <typename T>
void matrix<T>::printMatrix() {
for (size_t i=0;i<size;++i) {
for (size_t j=0;j<size;++j) if (data[i][j]>=INT32_MAX>>1) std::cout << '-' << '\t';
else std::cout << data[i][j] << '\t';
std::cout << std::endl;
}
std::cout << std::endl;
}
//necessary for linkage
template void matrix<int>::getMatrix(const char *fname);
template void matrix<int>::printMatrix();