mirror of
https://github.com/ToruNiina/toml11.git
synced 2025-12-16 03:08:52 +08:00
add example of table to README
This commit is contained in:
24
README.md
24
README.md
@@ -53,6 +53,8 @@ answer = 42
|
|||||||
pi = 3.14
|
pi = 3.14
|
||||||
numbers = [1,2,3]
|
numbers = [1,2,3]
|
||||||
time = 1979-05-27T07:32:00Z
|
time = 1979-05-27T07:32:00Z
|
||||||
|
[tab]
|
||||||
|
key = "value"
|
||||||
```
|
```
|
||||||
|
|
||||||
``` cpp
|
``` cpp
|
||||||
@@ -60,6 +62,8 @@ const auto answer = toml::get<std::int64_t>(data.at("answer"));
|
|||||||
const auto pi = toml::get<double>(data.at("pi"));
|
const auto pi = toml::get<double>(data.at("pi"));
|
||||||
const auto numbers = toml::get<std::vector<int>>(data.at("numbers"));
|
const auto numbers = toml::get<std::vector<int>>(data.at("numbers"));
|
||||||
const auto timepoint = toml::get<std::chrono::system_clock::time_point>(data.at("time"));
|
const auto timepoint = toml::get<std::chrono::system_clock::time_point>(data.at("time"));
|
||||||
|
const auto tab = toml::get<toml::Table>(data.at("tab"));
|
||||||
|
const auto key = toml::get<std::string>(tab.at("key"));
|
||||||
```
|
```
|
||||||
|
|
||||||
You can set any kind of `container` class to obtain `toml::Array` except for
|
You can set any kind of `container` class to obtain `toml::Array` except for
|
||||||
@@ -154,6 +158,26 @@ const auto ns = toml::get<std::vector<std::int64_t>>(a.at(0));
|
|||||||
const auto ss = toml::get<std::vector<std::string>>(a.at(1));
|
const auto ss = toml::get<std::vector<std::string>>(a.at(1));
|
||||||
```
|
```
|
||||||
|
|
||||||
|
#### Array of Table
|
||||||
|
|
||||||
|
Of course, you can obtain `array of table` in the same way.
|
||||||
|
|
||||||
|
```toml
|
||||||
|
array_of_inline_table = [{key = "value1"}, {key = "value2"}, {key = "value3"}]
|
||||||
|
|
||||||
|
[[array_of_table]]
|
||||||
|
key = "value4"
|
||||||
|
[[array_of_table]]
|
||||||
|
key = "value5"
|
||||||
|
[[array_of_table]]
|
||||||
|
key = "value6"
|
||||||
|
```
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
const auto aot1 = toml::get<std::vector<toml::Table>>(data.at("array_of_inline_table"))
|
||||||
|
const auto aot2 = toml::get<std::vector<toml::Table>>(data.at("array_of_table"))
|
||||||
|
```
|
||||||
|
|
||||||
## Documentation
|
## Documentation
|
||||||
|
|
||||||
The toml types are listed below.
|
The toml types are listed below.
|
||||||
|
|||||||
Reference in New Issue
Block a user