forked from awdeorio/csvstream
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example3.cpp
35 lines (29 loc) · 747 Bytes
/
example3.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
/* csvstream_example3.cpp
*
* Andrew DeOrio <[email protected]>
*
* An easy-to-use CSV file parser for C++
* https://github.com/awdeorio/csvstream
*/
#include "csvstream.h"
#include <iostream>
#include <string>
#include <vector>
#include <utility>
using namespace std;
int main() {
// Open file
csvstream csvin("input.csv");
// A row is a vector<pair<string, string>>
// key = column name, value = cell datum
vector<pair<string, string>> row;
// Read file
while (csvin >> row) {
cout << "row:" << "\n";
for (unsigned int i=0; i < row.size(); ++i) {
const string &column_name = row[i].first;
const string &datum = row[i].second;
cout << " " << column_name << ": " << datum << "\n";
}
}
}