-
Notifications
You must be signed in to change notification settings - Fork 62
/
LoadData.cpp
101 lines (98 loc) · 2.59 KB
/
LoadData.cpp
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#include <LoadData.h>
/**
加载数值型样本数据
*/
void LoadData_spare(Data &data, const std::string &infile)
{
std::cout<< "data filename is:"<< infile<<std::endl;
std::ifstream dataFile;
dataFile.open(infile);
std::string tmpstrline;
std::string onestr;
int pos = 0;
int index = 0;
double val = 0;
RowData rowData;
int line = 0;
if(dataFile)
{
while(!dataFile.eof())
{
getline(dataFile,tmpstrline,'\n');//读取文件中一行的数据,保存为string类型
std::stringstream input(tmpstrline);
if(tmpstrline!="\0")
{
while(input>>onestr)
{
pos = 0;
pos = onestr.find(":");
std::stringstream input_index(onestr.substr(0,pos));
std::stringstream input_val(onestr.substr(pos+1,onestr.size() - pos - 1));
input_index >> index;
input_val >> val;
std::cout<<"load_spare"<<onestr<<'\t'<<index<<'\t'<<val<<std::endl;
data[line][index] = val;
}
}
line++;
}
}
dataFile.close();
}
void LoadDataStr(RowDataStr &data, const std::string &infile)
{
std::cout<< "loaddatastr filename is:"<< infile<<std::endl;
std::ifstream dataFile;
dataFile.open(infile);
std::string tmpstrline;
std::string val;
RowDataStr rowData;
if(dataFile)
{
while(!dataFile.eof())
{
getline(dataFile,tmpstrline,'\n');//读取文件中一行的数据,保存为string类型
std::stringstream input(tmpstrline);
if(tmpstrline!="\0")
{
while(input>>val)
{
data.push_back(val);
}
}
}
}
dataFile.close();
}
/*
void LoadDataTest(Data &data, const std::string &infile)
{
std::cout<< "data filename is:"<< infile<<std::endl;
std::ifstream dataFile(infile);
std::string tmpstrline;
float val;
RowData rowData;
if(dataFile)
{
//while(dataFile>>)
while(!dataFile.eof())
{
getline(dataFile,tmpstrline,'\n');//读取文件中一行的数据,保存为string类型
std::stringstream input(tmpstrline);
if(tmpstrline!="\0")
{
while(input>>val)
{
rowData.push_back(val);
}
data.push_back(rowData);
}
rowData.clear();
}
}
else
{
std::cerr<< "data file open fail"<<std::endl;
}
dataFile.close();
}*/