MCPcopy Create free account
hub / github.com/danielaparker/jsoncons / csv_source_to_cpp_object

Function csv_source_to_cpp_object

examples/src/csv_examples.cpp:148–183  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

146}
147
148void csv_source_to_cpp_object()
149{
150 const std::string data = R"(Date,1Y,2Y,3Y,5Y
1512017-01-09,0.0062,0.0075,0.0083,0.011
1522017-01-08,0.0063,0.0076,0.0084,0.0112
1532017-01-08,0.0063,0.0076,0.0084,0.0112
154)";
155
156 auto ioptions = csv::csv_options{}
157 .header_lines(1)
158 .mapping_kind(csv::csv_mapping_kind::n_rows);
159
160 using table_type = std::vector<std::tuple<std::string,double,double,double,double>>;
161
162 table_type table = csv::decode_csv<table_type>(data,ioptions);
163
164 std::cout << "(1)\n";
165 for (const auto& row : table)
166 {
167 std::cout << std::get<0>(row) << ","
168 << std::get<1>(row) << ","
169 << std::get<2>(row) << ","
170 << std::get<3>(row) << ","
171 << std::get<4>(row) << "\n";
172 }
173 std::cout << "\n";
174
175 std::string output;
176
177 auto ooptions = csv::csv_options{}
178 .column_names("Date,1Y,2Y,3Y,5Y");
179 csv::encode_csv(table, output, ooptions);
180
181 std::cout << "(2)\n";
182 std::cout << output << "\n";
183}
184
185void csv_decode_without_type_inference()
186{

Callers 1

mainFunction · 0.85

Calls 3

encode_csvFunction · 0.85
mapping_kindMethod · 0.80
header_linesMethod · 0.80

Tested by

no test coverage detected