-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathio.h
More file actions
60 lines (52 loc) · 1.71 KB
/
Copy pathio.h
File metadata and controls
60 lines (52 loc) · 1.71 KB
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
//
// Created by adam on 6/30/19.
//
#ifndef CUDADB_IO_H
#define CUDADB_IO_H
#include <vector>
#include "recordType.h"
#include <fstream>
#include "recordType.h"
#include <boost/algorithm/string.hpp>
#include <boost/lexical_cast.hpp>
using namespace std;
std::ifstream file("data2.txt");
recordType string2recordType(string s){
recordType res;
try {
vector<string> strs;
boost::split(strs, s, boost::is_any_of("|"));
res = recordType(device_string(strs[1]), device_string(strs[2]), device_string(strs[3]), device_string(strs[4]),
device_string(strs[5]), boost::lexical_cast<int>(strs[6]), device_string(strs[7]),
device_string(strs[8]), device_string(strs[9]), device_string(strs[10]), device_string(strs[11]));
}
catch(const boost::bad_lexical_cast &e)
{
// 年龄用-1代替
vector<string> strs;
boost::split(strs, s, boost::is_any_of("|"));
res = recordType(device_string(strs[1]), device_string(strs[2]), device_string(strs[3]), device_string(strs[4]),
device_string(strs[5]), -1, device_string(strs[7]),
device_string(strs[8]), device_string(strs[9]), device_string(strs[10]), device_string(strs[11]));
}
catch(...) {
res = recordType();
}
return res;
}
vector<recordType> readFile(int maxLen) {
vector<recordType> vec;
string s;
while (getline(file, s) && vec.size()<maxLen) {
recordType rt = string2recordType(s);
if(rt.age!=-100){
// cout<<s<<endl;
vec.push_back(string2recordType(s));
}
else{
continue;
}
}
return vec;
}
#endif //CUDADB_IO_H