mirror of
https://github.com/ToruNiina/toml11.git
synced 2025-09-17 17:58:09 +08:00
126 lines
26 KiB
HTML
126 lines
26 KiB
HTML
![]() |
<!doctype html><html lang=en dir=ltr><head><meta charset=UTF-8><meta name=viewport content="width=device-width,initial-scale=1"><meta name=description content='
|
||
|
Outputting TOML Files
|
||
|
#
|
||
|
|
||
|
Using toml::format, you can convert a toml::value to a string.
|
||
|
#include <toml.hpp>
|
||
|
#include <cassert>
|
||
|
|
||
|
int main()
|
||
|
{
|
||
|
const toml::value v(toml::table{
|
||
|
{"a", 42},
|
||
|
{"b", "foo"},
|
||
|
});
|
||
|
const std::string s = toml::format(v);
|
||
|
|
||
|
const toml::value u = toml::parse_str(s);
|
||
|
|
||
|
assert(u.at("a").as_integer() == 42);
|
||
|
assert(u.at("b").as_string() == "foo");
|
||
|
|
||
|
return 0;
|
||
|
}
|
||
|
If the toml::value contains a table_type, it is interpreted as the root table of the file.
|
||
|
If a toml::value containing anything other than table_type is passed, only that value is formatted.'><meta name=theme-color media="(prefers-color-scheme: light)" content="#ffffff"><meta name=theme-color media="(prefers-color-scheme: dark)" content="#343a40"><meta name=color-scheme content="light dark"><meta property="og:url" content="https://toruniina.github.io/toml11/docs/features/serialize/"><meta property="og:site_name" content="toml11"><meta property="og:title" content="serializing values"><meta property="og:description" content='Outputting TOML Files # Using toml::format, you can convert a toml::value to a string.
|
||
|
#include <toml.hpp> #include <cassert> int main() { const toml::value v(toml::table{ {"a", 42}, {"b", "foo"}, }); const std::string s = toml::format(v); const toml::value u = toml::parse_str(s); assert(u.at("a").as_integer() == 42); assert(u.at("b").as_string() == "foo"); return 0; } If the toml::value contains a table_type, it is interpreted as the root table of the file.
|
||
|
If a toml::value containing anything other than table_type is passed, only that value is formatted.'><meta property="og:locale" content="en"><meta property="og:type" content="article"><meta property="article:section" content="docs"><title>serializing values | toml11</title>
|
||
|
<link rel=manifest href=/toml11/manifest.json><link rel=icon href=/toml11/favicon.png><link rel=canonical href=https://toruniina.github.io/toml11/docs/features/serialize/><link rel=alternate hreflang=ja href=https://toruniina.github.io/toml11/ja/docs/features/serialize/ title="serializing values"><link rel=stylesheet href=/toml11/book.min.ddac3efe7ea4c1007ff53e5a8fd67f12517e5d2e99984d8c67a18668f7ecaa03.css integrity="sha256-3aw+/n6kwQB/9T5aj9Z/ElF+XS6ZmE2MZ6GGaPfsqgM=" crossorigin=anonymous><script defer src=/toml11/fuse.min.js></script><script defer src=/toml11/en.search.min.db4a558804ac41f081539588cec8e4a415587801da466728166bb5341dd62411.js integrity="sha256-20pViASsQfCBU5WIzsjkpBVYeAHaRmcoFmu1NB3WJBE=" crossorigin=anonymous></script></head><body dir=ltr><input type=checkbox class="hidden toggle" id=menu-control>
|
||
|
<input type=checkbox class="hidden toggle" id=toc-control><main class="container flex"><aside class=book-menu><div class=book-menu-content><nav><h2 class=book-brand><a class="flex align-center" href=/toml11/><span>toml11</span></a></h2><div class="book-search hidden"><input type=text id=book-search-input placeholder=Search aria-label=Search maxlength=64 data-hotkeys=s/><div class="book-search-spinner hidden"></div><ul id=book-search-results></ul></div><script>document.querySelector(".book-search").classList.remove("hidden")</script><ul class=book-languages><li><input type=checkbox id=languages class=toggle>
|
||
|
<label for=languages class="flex justify-between"><a role=button class="flex align-center"><img src=/toml11/svg/translate.svg class=book-icon alt=Languages>
|
||
|
English</a></label><ul><li><a href=https://toruniina.github.io/toml11/ja/docs/features/serialize/>日本語</a></li></ul></li></ul><ul><li><a href=/toml11/docs/installation/>installation</a><ul></ul></li><li><input type=checkbox id=section-291123c850af98d8b815ccdbb4c33657 class=toggle checked>
|
||
|
<label for=section-291123c850af98d8b815ccdbb4c33657 class="flex justify-between"><a href=/toml11/docs/features/>features</a></label><ul><li><a href=/toml11/docs/features/parsing_files/>parsing files</a></li><li><a href=/toml11/docs/features/value/>getting values</a></li><li><a href=/toml11/docs/features/error_message/>error message</a></li><li><a href=/toml11/docs/features/serialize/ class=active>serializing values</a></li><li><a href=/toml11/docs/features/configure_types/>configuring types</a></li><li><a href=/toml11/docs/features/literal/>toml literal</a></li><li><a href=/toml11/docs/features/toml_spec/>toml spec</a></li><li><a href=/toml11/docs/features/extension/>extension</a></li></ul></li><li><input type=checkbox id=section-e2e812e55021b82e114feaae98f1a02e class=toggle>
|
||
|
<label for=section-e2e812e55021b82e114feaae98f1a02e class="flex justify-between"><a href=/toml11/docs/reference/>reference</a></label><ul><li><a href=/toml11/docs/reference/color/>color.hpp</a></li><li><a href=/toml11/docs/reference/comments/>comments.hpp</a></li><li><a href=/toml11/docs/reference/conversion/>conversion.hpp</a></li><li><a href=/toml11/docs/reference/datetime/>datetime.hpp</a></li><li><a href=/toml11/docs/reference/error_info/>error_info.hpp</a></li><li><a href=/toml11/docs/reference/exception/>exception.hpp</a></li><li><a href=/toml11/docs/reference/find/>find.hpp</a></li><li><a href=/toml11/docs/reference/format/>format.hpp</a></li><li><a href=/toml11/docs/reference/from/>from.hpp</a></li><li><a href=/toml11/docs/reference/get/>get.hpp</a></li><li><a href=/toml11/docs/reference/into/>into.hpp</a></li><li><a href=/toml11/docs/reference/literal/>literal.hpp</a></li><li><a href=/toml11/docs/reference/ordered_map/>ordered_map.hpp</a></li><li><a href=/toml11/docs/reference/parser/>parser.hpp</a></li><li><a href=/toml11/docs/reference/result/>result.hpp</a></li><li><a href=/toml11/docs/reference/serializer/>serializer.hpp</a></li><li><a href=/toml11/docs/reference/source_location/>source_location.hpp</a></li><li><a href=/toml11/docs/reference/spec/>spec.hpp</a></li><li><a href=/toml11/docs/reference/toml_fwd/>toml_fwd.hpp</a></li><li><a href=/toml11/docs/reference/toml/>toml.hpp</a></li><li><a href=/toml11/docs/reference/types/>types.hpp</a></li><li><a href=/toml11/docs/reference/value_t/>value_t.hpp</a></li><li><a href=/toml11/docs/reference/value/>value.hpp</a></li><li><a href=/toml11/docs/reference/version/>version.hpp</a></li><li><a href=/toml11/docs/reference/visit/>visit.hpp</a></li></ul></li><li><a href=/toml11/docs/changelog/>changelog</a><ul></ul></li></ul><ul><li><a href=https://github.com/ToruNiina/toml11 target=_blank rel=noopener>GitHub</a></li></ul></nav><script>(function(){var e=document.querySelector("aside .book-menu-content");addEventListener("beforeunload",function(){localStorage.setItem("menu.scrollTop",e.scrollTop)}),e.scrollTop=localStorage.getItem("menu.scrollTop")})()</script></div></aside><div class=book-page><header class=book-header><div class="flex align-center justify-between"><label for=menu-control><img src=/toml11/svg/menu.svg class=book-icon alt=Menu>
|
||
|
</label><strong>serializing values</strong>
|
||
|
<label for=toc-control><img src=/toml11/svg/toc.svg class=book-icon alt="Table of Contents"></label></div><aside class="hidden clearfix"><nav id=TableOfContents><ul><li><a href=#outputting-toml-files>Outputting TOML Files</a><ul><li><a href=#outputting-with-keys>Outputting with Keys</a></li><li><a href=#specifying-formats>Specifying Formats</a><ul><li><a href=#specifying-integer-formats>Specifying Integer Formats</a></li><li><a href=#single-line-and-multi-line-arrays>Single-Line and Multi-Line Arrays</a></li><li><a href=#inline-tables>Inline Tables</a></li></ul></li><li><a href=#specifying-the-toml-language-version-for-output>Specifying the TOML Language Version for Output</a></li></ul></li></ul></nav></aside></header><article class="markdown book-article"><h1 id=outputting-toml-files>Outputting TOML Files
|
||
|
<a class=anchor href=#outputting-toml-files>#</a></h1><p>Using <code>toml::format</code>, you can convert a <code>toml::value</code> to a string.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#75715e>#include</span> <span style=color:#75715e><toml.hpp></span><span style=color:#75715e>
|
||
|
</span></span></span><span style=display:flex><span><span style=color:#75715e>#include</span> <span style=color:#75715e><cassert></span><span style=color:#75715e>
|
||
|
</span></span></span><span style=display:flex><span><span style=color:#75715e></span>
|
||
|
</span></span><span style=display:flex><span><span style=color:#66d9ef>int</span> <span style=color:#a6e22e>main</span>()
|
||
|
</span></span><span style=display:flex><span>{
|
||
|
</span></span><span style=display:flex><span> <span style=color:#66d9ef>const</span> toml<span style=color:#f92672>::</span>value v(toml<span style=color:#f92672>::</span>table{
|
||
|
</span></span><span style=display:flex><span> {<span style=color:#e6db74>"a"</span>, <span style=color:#ae81ff>42</span>},
|
||
|
</span></span><span style=display:flex><span> {<span style=color:#e6db74>"b"</span>, <span style=color:#e6db74>"foo"</span>},
|
||
|
</span></span><span style=display:flex><span> });
|
||
|
</span></span><span style=display:flex><span> <span style=color:#66d9ef>const</span> std<span style=color:#f92672>::</span>string s <span style=color:#f92672>=</span> toml<span style=color:#f92672>::</span>format(v);
|
||
|
</span></span><span style=display:flex><span>
|
||
|
</span></span><span style=display:flex><span> <span style=color:#66d9ef>const</span> toml<span style=color:#f92672>::</span>value u <span style=color:#f92672>=</span> toml<span style=color:#f92672>::</span>parse_str(s);
|
||
|
</span></span><span style=display:flex><span>
|
||
|
</span></span><span style=display:flex><span> assert(u.at(<span style=color:#e6db74>"a"</span>).as_integer() <span style=color:#f92672>==</span> <span style=color:#ae81ff>42</span>);
|
||
|
</span></span><span style=display:flex><span> assert(u.at(<span style=color:#e6db74>"b"</span>).as_string() <span style=color:#f92672>==</span> <span style=color:#e6db74>"foo"</span>);
|
||
|
</span></span><span style=display:flex><span>
|
||
|
</span></span><span style=display:flex><span> <span style=color:#66d9ef>return</span> <span style=color:#ae81ff>0</span>;
|
||
|
</span></span><span style=display:flex><span>}
|
||
|
</span></span></code></pre></div><p>If the <code>toml::value</code> contains a <code>table_type</code>, it is interpreted as the root table of the file.</p><p>If a <code>toml::value</code> containing anything other than <code>table_type</code> is passed, only that value is formatted.</p><p>Certain format specifications may require a key to be provided for formatting. For example, <code>toml::array_format::array_of_tables</code> formats as <code>[[array.of.tables]]</code>, which requires key access.</p><p>If a format specification that requires a key is provided without a key, a <code>toml::serialization_error</code> is thrown.</p><p>Additionally, if there are values that contradict the format specification, a <code>toml::serialization_error</code> is thrown. For instance, specifying <code>integer_format::hex</code> for a negative integer, or <code>string_format::literal</code> for a string containing newlines, will cause an error.</p><p>The method for specifying formats is explained later.</p><h2 id=outputting-with-keys>Outputting with Keys
|
||
|
<a class=anchor href=#outputting-with-keys>#</a></h2><p>You can pass a key to <code>toml::format</code> as a <code>std::string</code>.</p><p>In this case, the key is considered to be under the root table, and the passed value corresponds to that key.</p><p>For nested keys, you can pass a <code>std::vector<std::string></code>.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#75715e>#include</span> <span style=color:#75715e><toml.hpp></span><span style=color:#75715e>
|
||
|
</span></span></span><span style=display:flex><span><span style=color:#75715e>#include</span> <span style=color:#75715e><cassert></span><span style=color:#75715e>
|
||
|
</span></span></span><span style=display:flex><span><span style=color:#75715e></span>
|
||
|
</span></span><span style=display:flex><span><span style=color:#66d9ef>int</span> <span style=color:#a6e22e>main</span>()
|
||
|
</span></span><span style=display:flex><span>{
|
||
|
</span></span><span style=display:flex><span> <span style=color:#66d9ef>const</span> toml<span style=color:#f92672>::</span>value v(toml<span style=color:#f92672>::</span>table{
|
||
|
</span></span><span style=display:flex><span> {<span style=color:#e6db74>"a"</span>, <span style=color:#ae81ff>42</span>},
|
||
|
</span></span><span style=display:flex><span> {<span style=color:#e6db74>"b"</span>, <span style=color:#e6db74>"foo"</span>},
|
||
|
</span></span><span style=display:flex><span> });
|
||
|
</span></span><span style=display:flex><span> <span style=color:#66d9ef>const</span> std<span style=color:#f92672>::</span>string s <span style=color:#f92672>=</span> toml<span style=color:#f92672>::</span>format(<span style=color:#e6db74>"bar"</span>, v);
|
||
|
</span></span><span style=display:flex><span>
|
||
|
</span></span><span style=display:flex><span> <span style=color:#66d9ef>const</span> toml<span style=color:#f92672>::</span>value u <span style=color:#f92672>=</span> toml<span style=color:#f92672>::</span>parse_str(s);
|
||
|
</span></span><span style=display:flex><span>
|
||
|
</span></span><span style=display:flex><span> assert(u.at(<span style=color:#e6db74>"bar"</span>).at(<span style=color:#e6db74>"a"</span>).as_integer() <span style=color:#f92672>==</span> <span style=color:#ae81ff>42</span>);
|
||
|
</span></span><span style=display:flex><span> assert(u.at(<span style=color:#e6db74>"bar"</span>).at(<span style=color:#e6db74>"b"</span>).as_string() <span style=color:#f92672>==</span> <span style=color:#e6db74>"foo"</span>);
|
||
|
</span></span><span style=display:flex><span>
|
||
|
</span></span><span style=display:flex><span> <span style=color:#66d9ef>return</span> <span style=color:#ae81ff>0</span>;
|
||
|
</span></span><span style=display:flex><span>}
|
||
|
</span></span></code></pre></div><h2 id=specifying-formats>Specifying Formats
|
||
|
<a class=anchor href=#specifying-formats>#</a></h2><p>Each type in <code>toml::value</code> has a corresponding format information type.</p><p>For <code>toml::value::integer_type</code>, there is <code>toml::integer_format_info</code>.
|
||
|
For <code>toml::value::table_type</code>, there is <code>toml::table_format_info</code>.</p><p>These format information types are set when parsing and are retained even if the value is changed, as long as the type remains the same.</p><p>You can access and directly edit these formats using member functions like <code>as_integer_fmt()</code> or <code>as_table_fmt()</code>.</p><p>Below are some examples explaining how to use these formats.</p><p>For more details on how to access formats, refer to the <a href=https://toruniina.github.io/toml11/docs/reference/value/><code>toml::value</code> reference</a>. For a complete list and detailed information on format information classes, see the <a href=https://toruniina.github.io/toml11/docs/reference/format/>format reference</a>.</p><h3 id=specifying-integer-formats>Specifying Integer Formats
|
||
|
<a class=anchor href=#specifying-integer-formats>#</a></h3><p>For integers, you can specify the radix, width, and the position of <code>_</code>.</p><p>When using <code>hex</code>, <code>oct</code>, or <code>bin</code>, values are padded with zeros until the specified width is reached. For <code>dec</code>, the width specification adds spaces, which are not parsed.</p><p>For more details, see the <a href=https://toruniina.github.io/toml11/docs/reference/format/#integer_format>integer format reference</a>.</p><h3 id=single-line-and-multi-line-arrays>Single-Line and Multi-Line Arrays
|
||
|
<a class=anchor href=#single-line-and-multi-line-arrays>#</a></h3><p>For arrays, you can specify <code>toml::array_format::oneline</code> or <code>toml::array_format::multiline</code>.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-toml data-lang=toml><span style=display:flex><span><span style=color:#75715e># oneline</span>
|
||
|
</span></span><span style=display:flex><span><span style=color:#a6e22e>a</span> = [<span style=color:#ae81ff>1</span>, <span style=color:#ae81ff>2</span>, <span style=color:#ae81ff>3</span>, <span style=color:#ae81ff>4</span>, <span style=color:#ae81ff>5</span>]
|
||
|
</span></span><span style=display:flex><span><span style=color:#75715e># multiline</span>
|
||
|
</span></span><span style=display:flex><span><span style=color:#a6e22e>a</span> = [
|
||
|
</span></span><span style=display:flex><span> <span style=color:#ae81ff>1</span>,
|
||
|
</span></span><span style=display:flex><span> <span style=color:#ae81ff>2</span>,
|
||
|
</span></span><span style=display:flex><span> <span style=color:#ae81ff>3</span>,
|
||
|
</span></span><span style=display:flex><span> <span style=color:#ae81ff>4</span>,
|
||
|
</span></span><span style=display:flex><span> <span style=color:#ae81ff>5</span>
|
||
|
</span></span><span style=display:flex><span>]
|
||
|
</span></span></code></pre></div><p>When using <code>multiline</code>, you can specify the indentation. Each element is indented by the amount specified in <code>body_indent</code>, and the closing bracket <code>]</code> is indented by the amount specified in <code>closing_indent</code>.</p><p>The type of character used for indentation is specified by <code>indent_type</code>, and you can choose between <code>toml::indent_char::space</code> or <code>toml::indent_char::tab</code>.</p><blockquote class="book-hint warning"><p>Ensure that the same type of character is used for indentation throughout the document.</p><p>If different types of characters are specified for indentation within the same file, the result is undefined. Some form of indentation will be applied, but the type of character and the depth of the indentation may be inconsistent.</p></blockquote><p>If all elements of an <code>array</code> have <code>table_type</code>, you can specify <code>toml::array_format::array_of_tables</code>.</p><p>If you do not specify <code>array_of_tables</code> and use <code>multiline</code>, the tables will be formatted as inline tables.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-toml data-lang=toml><span style=display:flex><span><span style=color:#75715e># multiline</span>
|
||
|
</span></span><span style=display:flex><span><span style=color:#a6e22e>a</span> = [
|
||
|
</span></span><span style=display:flex><span> {<span style=color:#a6e22e>foo</span> = <span style=color:#ae81ff>42</span>},
|
||
|
</span></span><span style=display:flex><span> {<span style=color:#a6e22e>bar</span> = <span style=color:#e6db74>"hoge"</span>},
|
||
|
</span></span><span style=display:flex><span>]
|
||
|
</span></span><span style=display:flex><span>
|
||
|
</span></span><span style=display:flex><span><span style=color:#75715e># array_of_tables</span>
|
||
|
</span></span><span style=display:flex><span>[[<span style=color:#a6e22e>a</span>]]
|
||
|
</span></span><span style=display:flex><span><span style=color:#a6e22e>foo</span> = <span style=color:#ae81ff>42</span>
|
||
|
</span></span><span style=display:flex><span>
|
||
|
</span></span><span style=display:flex><span>[[<span style=color:#a6e22e>a</span>]]
|
||
|
</span></span><span style=display:flex><span><span style=color:#a6e22e>bar</span> = <span style=color:#e6db74>"hoge"</span>
|
||
|
</span></span></code></pre></div><p>By default, <code>toml::array_format::default_format</code> is used. This automatically selects an appropriate format.</p><p>For example, with <code>default_format</code>, if all elements are <code>table_type</code>, it will choose <code>array_of_tables</code>. Short arrays are formatted as <code>oneline</code>, while long or nested arrays, or those with complex elements, are formatted as <code>multiline</code>.</p><p>For more details, see the <a href=https://toruniina.github.io/toml11/docs/reference/format/#array_format>array format reference</a>.</p><h3 id=inline-tables>Inline Tables
|
||
|
<a class=anchor href=#inline-tables>#</a></h3><p>To format a table as an inline table, specify <code>toml::table_format::oneline</code>.
|
||
|
For standard tables, use <code>toml::table_format::multiline</code>.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-toml data-lang=toml><span style=display:flex><span><span style=color:#a6e22e>oneline</span> = {<span style=color:#a6e22e>a</span> = <span style=color:#ae81ff>42</span>, <span style=color:#a6e22e>b</span> = <span style=color:#e6db74>"foo"</span>}
|
||
|
</span></span><span style=display:flex><span>
|
||
|
</span></span><span style=display:flex><span>[<span style=color:#a6e22e>multiline</span>]
|
||
|
</span></span><span style=display:flex><span><span style=color:#a6e22e>a</span> = <span style=color:#ae81ff>42</span>
|
||
|
</span></span><span style=display:flex><span><span style=color:#a6e22e>b</span> = <span style=color:#e6db74>"foo"</span>
|
||
|
</span></span></code></pre></div><p>In TOML v1.1.0, line breaks within inline tables are allowed. In this case, use <code>toml::table_format::multiline_oneline</code>. This is only applied if the corresponding feature flag is set to <code>true</code> as per the TOML version specification described later.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-toml data-lang=toml><span style=display:flex><span><span style=color:#a6e22e>multiline_oneline</span> = {
|
||
|
</span></span><span style=display:flex><span> <span style=color:#a6e22e>a</span> = <span style=color:#ae81ff>42</span>,
|
||
|
</span></span><span style=display:flex><span> <span style=color:#a6e22e>b</span> = <span style=color:#e6db74>"foo"</span>
|
||
|
</span></span><span style=display:flex><span>}
|
||
|
</span></span></code></pre></div><p>For more details, see the <a href=https://toruniina.github.io/toml11/docs/reference/format/#table_format>table format reference</a>.</p><h2 id=specifying-the-toml-language-version-for-output>Specifying the TOML Language Version for Output
|
||
|
<a class=anchor href=#specifying-the-toml-language-version-for-output>#</a></h2><p>Certain language features, such as line breaks within inline tables and <code>\x</code> escape sequences, are only available after TOML v1.1.0.</p><p>The <code>toml::format</code> function accepts a <code>toml::spec</code> as its argument.</p><p>This allows you to specify the version of TOML to use during serialization.</p><p>When you use <code>toml::parse</code> with a <code>toml::spec</code> to leverage new features,
|
||
|
the parsed values may contain format information that is only compatible with that specific version.
|
||
|
Ensure that you pass the same <code>toml::spec</code> to <code>toml::format</code> to maintain compatibility.</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-cpp data-lang=cpp><span style=display:flex><span><span style=color:#75715e>#include</span> <span style=color:#75715e><toml.hpp></span><span style=color:#75715e>
|
||
|
</span></span></span><span style=display:flex><span><span style=color:#75715e>#include</span> <span style=color:#75715e><iostream></span><span style=color:#75715e>
|
||
|
</span></span></span><span style=display:flex><span><span style=color:#75715e></span>
|
||
|
</span></span><span style=display:flex><span><span style=color:#66d9ef>int</span> <span style=color:#a6e22e>main</span>()
|
||
|
</span></span><span style=display:flex><span>{
|
||
|
</span></span><span style=display:flex><span> <span style=color:#66d9ef>const</span> <span style=color:#66d9ef>auto</span> spec <span style=color:#f92672>=</span> toml<span style=color:#f92672>::</span>spec<span style=color:#f92672>::</span>v(<span style=color:#ae81ff>1</span>, <span style=color:#ae81ff>1</span>, <span style=color:#ae81ff>0</span>);
|
||
|
</span></span><span style=display:flex><span>
|
||
|
</span></span><span style=display:flex><span> <span style=color:#66d9ef>const</span> toml<span style=color:#f92672>::</span>value v <span style=color:#f92672>=</span> toml<span style=color:#f92672>::</span>parse(<span style=color:#e6db74>"input.toml"</span>, spec);
|
||
|
</span></span><span style=display:flex><span>
|
||
|
</span></span><span style=display:flex><span> std<span style=color:#f92672>::</span>cout <span style=color:#f92672><<</span> toml<span style=color:#f92672>::</span>format(v, spec) <span style=color:#f92672><<</span> std<span style=color:#f92672>::</span>endl;
|
||
|
</span></span><span style=display:flex><span>
|
||
|
</span></span><span style=display:flex><span> <span style=color:#66d9ef>return</span> <span style=color:#ae81ff>0</span>;
|
||
|
</span></span><span style=display:flex><span>}
|
||
|
</span></span></code></pre></div></article><footer class=book-footer><div class="flex flex-wrap justify-between"></div><script>(function(){function e(e){const t=window.getSelection(),n=document.createRange();n.selectNodeContents(e),t.removeAllRanges(),t.addRange(n)}document.querySelectorAll("pre code").forEach(t=>{t.addEventListener("click",function(){if(window.getSelection().toString())return;e(t.parentElement),navigator.clipboard&&navigator.clipboard.writeText(t.parentElement.textContent)})})})()</script></footer><label for=menu-control class="hidden book-menu-overlay"></label></div><aside class=book-toc><div class=book-toc-content><nav id=TableOfContents><ul><li><a href=#outputting-toml-files>Outputting TOML Files</a><ul><li><a href=#outputting-with-keys>Outputting with Keys</a></li><li><a href=#specifying-formats>Specifying Formats</a><ul><li><a href=#specifying-integer-formats>Specifying Integer Formats</a></li><li><a href=#single-line-and-multi-line-arrays>Single-Line and Multi-Line Arrays</a></li><li><a href=#inline-tables>Inline Tables</a></li></ul></li><li><a href=#specifying-the-toml-language-version-for-output>Specifying the TOML Language Version for Output</a></li></ul></li></ul></nav></div></aside></main></body></html>
|