#include #include #include #include #include #include #include // libcurl hands the body over in pieces: append each one to a string static size_t append(char* data, size_t size, size_t n, void* body) { static_cast(body)->append(data, size * n); return size * n; } int main() { // Read VOO's file (one GET, no key), naming your own project std::string body; CURL* curl = curl_easy_init(); curl_easy_setopt(curl, CURLOPT_URL, "https://tickerinside.com/api/v1/fund/voo.json"); curl_easy_setopt(curl, CURLOPT_USERAGENT, "MyProject/1.0 (+https://example.com)"); curl_easy_setopt(curl, CURLOPT_FAILONERROR, 1L); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, append); curl_easy_setopt(curl, CURLOPT_WRITEDATA, &body); CURLcode rc = curl_easy_perform(curl); curl_easy_cleanup(curl); if (rc != CURLE_OK) { std::cerr << curl_easy_strerror(rc) << "\n"; return 1; } auto fund = nlohmann::json::parse(body); // The date of the issuer's file the weights come from std::cout << "VOO holdings_as_of " << fund["holdings_as_of"].get() << "\n"; // holdings maps each ticker to its weight in percent: largest first std::vector> rows; for (auto& [ticker, weight] : fund["holdings"].items()) { rows.emplace_back(ticker, weight.get()); } std::stable_sort(rows.begin(), rows.end(), [](const auto& a, const auto& b) { return a.second > b.second; }); std::cout << rows.size() << " holdings, largest first\n"; for (auto& [ticker, weight] : rows) { std::cout << ticker << " " << weight << "\n"; } // The line to print under any figure you quote std::cout << fund["cite_as"].get() << "\n"; }