-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfile_parser.cpp
More file actions
51 lines (42 loc) · 1.15 KB
/
Copy pathfile_parser.cpp
File metadata and controls
51 lines (42 loc) · 1.15 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
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <iterator>
#include <string>
int main(){
// stl containers
std::map<std::string, std::string> index;
std::pair<std::string, std::string> x;
std::vector<std::string> keys;
// file stream
std::ifstream file;
std::string line;
std::string f_name = "filename";
file.open(f_name);
if (file.is_open()){
while (std::getline(file,line) ){
// get the break points of the data
std::size_t sub = line.find(",");
std::size_t sub2 = line.find("\n");
// insert the data into a map
x.first = line.substr(0, sub);
keys.push_back(line.substr(0, sub));
x.second = line.substr(sub+1, sub2);
index.insert(x);
}
file.close();
}
else{
std::cout << "File could not be opned\n";
}
// output the contents of the map
std::for_each(keys.rbegin(), keys.rend(),
[&index](std::string k){
std::cout << index[k] << std::endl;
});
// store tabular data
std::multimap<std::string, std::vector<std::string>> data_frame = {{ "pluto", { "dog", "10", "male" } }};
std::string file = "filename";
return 0;
}