forked from awdeorio/csvstream
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample2.cpp
More file actions
33 lines (27 loc) · 676 Bytes
/
example2.cpp
File metadata and controls
33 lines (27 loc) · 676 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
/* example2.cpp
*
* Andrew DeOrio <awdeorio@umich.edu>
*
* csvstream: An easy-to-use CSV file parser for C++
* https://github.com/awdeorio/csvstream
*/
#include "csvstream.hpp"
#include <iostream>
#include <string>
#include <map>
using namespace std;
int main() {
// Open file
csvstream csvin("input.csv");
// A row is a map<string, string>, key = column name, value = cell datum
map<string, string> row;
// Read file
while (csvin >> row) {
cout << "row:" << "\n";
for (auto &col:row) {
const string &column_name = col.first;
const string &datum = col.second;
cout << " " << column_name << ": " << datum << "\n";
}
}
}