mirror of
https://github.com/marzer/tomlplusplus.git
synced 2024-11-02 02:26:28 +00:00
0ffd23d73f
also: - renamed `TOML_WINDOWS_COMPAT` to `TOML_ENABLE_WINDOWS_COMPAT` - renamed `TOML_UNRELEASED_FEATURES` to `TOML_ENABLE_UNRELEASED_FEATURES` - added additional tests - fixed minor documentation issues
39 lines
975 B
C++
39 lines
975 B
C++
// This file is a part of toml++ and is subject to the the terms of the MIT license.
|
|
// Copyright (c) Mark Gillard <mark.gillard@outlook.com.au>
|
|
// See https://github.com/marzer/tomlplusplus/blob/master/LICENSE for the full license text.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
// This example demonstrates how to use the toml::json_formatter to re-serialize TOML data as JSON.
|
|
|
|
#include "examples.h"
|
|
|
|
#define TOML_ENABLE_UNRELEASED_FEATURES 1
|
|
#include <toml++/toml.h>
|
|
|
|
using namespace std::string_view_literals;
|
|
|
|
int main(int argc, char** argv)
|
|
{
|
|
toml::table table;
|
|
try
|
|
{
|
|
// read from a file if a path argument is given
|
|
if (argc > 1)
|
|
table = toml::parse_file(argv[1]);
|
|
|
|
// otherwise read directly from stdin
|
|
else
|
|
table = toml::parse(std::cin, "stdin"sv);
|
|
|
|
std::cout << toml::json_formatter{ table } << "\n";
|
|
}
|
|
catch (const toml::parse_error& err)
|
|
{
|
|
std::cerr << err << "\n";
|
|
return 1;
|
|
}
|
|
|
|
std::cout << toml::json_formatter{ table } << "\n";
|
|
return 0;
|
|
}
|