You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
914 B

4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
  1. #include <iostream>
  2. #include <string>
  3. #include <string_view>
  4. #include <toml++/toml.hpp>
  5. // g++ tomldemo.cpp -I ../libs/tomlplusplus -std=c++17
  6. // https://marzer.github.io/tomlplusplus/
  7. using namespace std::literals;
  8. int main(int argc, char** argv) {
  9. toml::table tbl;
  10. try {
  11. tbl = toml::parse_file("config.ini");
  12. std::cout << tbl << "\n";
  13. std::cout << (toml::json_formatter{tbl}) << "\n\n";
  14. if (auto channels = tbl["channels"].as_array()) {
  15. channels->for_each([&](auto&& ch) { //
  16. std::cout << (toml::json_formatter{ch}) << "\n";
  17. });
  18. }
  19. // tbl["server"]["port"] ;
  20. std::cout <<"server.cmdport:"<< tbl["server"]["cmdport"].value_or(19004) << "\n";
  21. std::cout <<"server.wsport:"<< tbl["server"]["wsport"].value_or(19005) << "\n";
  22. } catch (const toml::parse_error& err) {
  23. std::cerr << "Parsing failed:\n" << err << "\n";
  24. return 1;
  25. }
  26. return 0;
  27. }