mirror of
https://github.com/marzer/tomlplusplus.git
synced 2025-02-24 03:40:13 +00:00
also: - fixed truncation of floating-point values when using ostreams - fixed some minor documentation issues (fixes #8) - fixed missing value deduction guides for dates and times - added serialization round-trip tests (closes #9) - added node::is_number() - added node_view::is_number() - added node_view::value_or() (closes #7) - added hexfloat parsing support for all implementations, not just <charconv> ones
40 lines
846 B
C++
40 lines
846 B
C++
#include <iostream>
|
|
#include <fstream>
|
|
#include <toml++/toml.h>
|
|
#ifdef _WIN32
|
|
#define WIN32_LEAN_AND_MEAN
|
|
#include <Windows.h>
|
|
#endif
|
|
using namespace std::string_view_literals;
|
|
|
|
int main(int argc, char** argv)
|
|
{
|
|
#ifdef _WIN32
|
|
SetConsoleOutputCP(65001); //UTF-8 console output
|
|
#endif
|
|
|
|
auto path = std::string{ argc > 1 ? argv[1] : "example.toml" };
|
|
auto file = std::ifstream{ path };
|
|
if (!file)
|
|
{
|
|
std::cerr << "The file '"sv << path << "' could not be opened for reading."sv << std::endl;
|
|
return 1;
|
|
}
|
|
try
|
|
{
|
|
const auto tbl = toml::parse(file, std::move(path));
|
|
std::cout << tbl << std::endl;
|
|
}
|
|
catch (const toml::parse_error& err)
|
|
{
|
|
std::cerr
|
|
<< "Error parsing file '"sv << *err.source().path
|
|
<< "':\n"sv << err.description()
|
|
<< "\n ("sv << err.source().begin << ")"sv
|
|
<< std::endl;
|
|
|
|
return 1;
|
|
}
|
|
return 0;
|
|
}
|