From 18986978fb12abb0f22d1d00cef4ad41a67fae6e Mon Sep 17 00:00:00 2001 From: ToruNiina Date: Sun, 24 Mar 2019 21:30:27 +0900 Subject: [PATCH] chore: add short example code to README --- README.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/README.md b/README.md index 28d8441..ed28ec2 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,28 @@ Not only the test suite itself, a TOML reader/encoder also runs on [CircleCI](ht You can see the error messages about invalid files and serialization results of valid files at [CircleCI](https://circleci.com/gh/ToruNiina/toml11). +## Example + +```cpp +#include +#include + +int main() +{ + const auto data = toml::parse("example.toml"); + + // title = "an example toml file" + std::string title = toml::get(data.at("title")); + std::cout << "the title is " << title << std::endl; + + // nums = [1, 2, 3, 4, 5] + std::vector nums = toml::get>(data.at("nums")); + std::cout << "the length of `nums` is" << nums.size() << std::endl; + + return 0; +} +``` + ## Table of Contents - [Integration](#integration) @@ -53,12 +75,14 @@ Just include the file after adding it to the include path. ```cpp #include // that's all! now you can use it. +#include int main() { const auto data = toml::parse("example.toml"); const auto title = toml::get(data.at("title")); std::cout << "the title is " << title << std::endl; + return 0; } ```