-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample01.cpp
33 lines (28 loc) · 1.23 KB
/
example01.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
#include <cassert> // for assert
#include <iostream>
#include <vector>
#include "quickcsv.hpp"
void test_example1(std::string const& filename) {
// get all columns: symbol,open,high,low,close,volume
// the parsing types is: <std::string, double, double, double, double, int> related to column index
auto [symbol_vec, open_vec, high_vec, low_vec, close_vec, volume_vec] = quickcsv::read_csv<std::string, double, double, double, double, int>(filename);
assert(typeid(symbol_vec) == typeid(std::vector<std::string>));
assert(typeid(open_vec) == typeid(std::vector<double>));
assert(typeid(high_vec) == typeid(std::vector<double>));
assert(typeid(low_vec) == typeid(std::vector<double>));
assert(typeid(close_vec) == typeid(std::vector<double>));
assert(typeid(volume_vec) == typeid(std::vector<int>));
size_t vect_size = symbol_vec.size();
for (unsigned i = 0; i < vect_size; ++i) {
std::cout << symbol_vec[i] << '\t';
std::cout << open_vec[i] << '\t';
std::cout << high_vec[i] << '\t';
std::cout << low_vec[i] << '\t';
std::cout << close_vec[i] << '\t';
std::cout << volume_vec[i] << '\n';
}
}
int main() {
test_example1("csv/en.csv");
return 0;
}