MCPcopy Create free account
hub / github.com/boostorg/parser / main

Function main

example/json.cpp:336–362  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

334}
335
336int main(int argc, char * argv[])
337{
338 if (argc < 2) {
339 std::cerr << "A filename to parse is required.\n";
340 exit(1);
341 }
342
343 std::ifstream ifs(argv[1]);
344 if (!ifs) {
345 std::cerr << "Unable to read file '" << argv[1] << "'.\n";
346 exit(1);
347 }
348
349 // Read in the entire file.
350 std::string const file_contents = file_slurp(ifs);
351 // Parse the contents. If there is an error, just stream it to cerr.
352 auto json = json::parse(
353 file_contents, [](std::string const & msg) { std::cerr << msg; });
354 if (!json) {
355 std::cerr << "Parse failure.\n";
356 exit(1);
357 }
358
359 std::cout << "Parse successful; contents:\n" << *json << "\n";
360
361 return 0;
362}
363//]

Callers

nothing calls this directly

Calls 2

file_slurpFunction · 0.70
parseFunction · 0.70

Tested by

no test coverage detected