* Docs: fill documentation gaps found in user questions Add pages on class-hierarchy/smart-pointer/variant/chrono recipes, working without exceptions, and large, streamed and partial input. Extend the FAQ (23 entries, Known bugs first), parse error documentation (empty-input checklist, line/column, diagnostic positions), element access, conversions, creating values, ADL troubleshooting, memory, and build/distribution notes. Add 14 examples with generated output. Correct the statement that parse errors cannot be recovered from with -fno-exceptions. The topics come from recurring questions on Stack Overflow, Reddit, Hacker News, YouTube, and the project's GitHub discussions and issues. Signed-off-by: Niels Lohmann <mail@nlohmann.me> * docs: declare range-for lists in variables to keep astyle quiet astyle reformats a braced init list placed directly in a range-for header; declare the list first so check_amalgamation passes. Signed-off-by: Niels Lohmann <mail@nlohmann.me> --------- Signed-off-by: Niels Lohmann <mail@nlohmann.me>
24 lines
625 B
C++
24 lines
625 B
C++
#include <iostream>
|
|
#include <sstream>
|
|
#include <nlohmann/json.hpp>
|
|
|
|
using json = nlohmann::json;
|
|
|
|
int main()
|
|
{
|
|
// a CBOR value followed by other data
|
|
const std::vector<std::uint8_t> cbor = json::to_cbor(json{1, 2, 3});
|
|
std::string data(cbor.begin(), cbor.end());
|
|
data += "TRAILING";
|
|
|
|
std::istringstream input(data);
|
|
json j = json::from_cbor(input, false); // strict = false: stop after the first value
|
|
|
|
std::cout << "value: " << j << '\n';
|
|
std::cout << "bytes used: " << input.tellg() << '\n';
|
|
|
|
std::string rest;
|
|
input >> rest;
|
|
std::cout << "remaining input: " << rest << '\n';
|
|
}
|