build_toml.cpp 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #include <cpptoml.h>
  2. #include <iostream>
  3. int main(int argc, char* argv[])
  4. {
  5. std::shared_ptr<cpptoml::table> root = cpptoml::make_table();
  6. root->insert("Integer", 1234L);
  7. root->insert("Double", 1.234);
  8. root->insert("String", std::string("ABCD"));
  9. auto table = cpptoml::make_table();
  10. table->insert("ElementOne", 1L);
  11. table->insert("ElementTwo", 2.0);
  12. table->insert("ElementThree", std::string("THREE"));
  13. auto nested_table = cpptoml::make_table();
  14. nested_table->insert("ElementOne", 2L);
  15. nested_table->insert("ElementTwo", 3.0);
  16. nested_table->insert("ElementThree", std::string("FOUR"));
  17. table->insert("Nested", nested_table);
  18. root->insert("Table", table);
  19. auto int_array = cpptoml::make_array();
  20. int_array->push_back(1L);
  21. int_array->push_back(2L);
  22. int_array->push_back(3L);
  23. int_array->push_back(4L);
  24. int_array->push_back(5L);
  25. root->insert("IntegerArray", int_array);
  26. auto double_array = cpptoml::make_array();
  27. double_array->push_back(1.1);
  28. double_array->push_back(2.2);
  29. double_array->push_back(3.3);
  30. double_array->push_back(4.4);
  31. double_array->push_back(5.5);
  32. root->insert("DoubleArray", double_array);
  33. auto string_array = cpptoml::make_array();
  34. string_array->push_back(std::string("A"));
  35. string_array->push_back(std::string("B"));
  36. string_array->push_back(std::string("C"));
  37. string_array->push_back(std::string("D"));
  38. string_array->push_back(std::string("E"));
  39. root->insert("StringArray", string_array);
  40. auto table_array = cpptoml::make_table_array();
  41. table_array->push_back(table);
  42. table_array->push_back(table);
  43. table_array->push_back(table);
  44. root->insert("TableArray", table_array);
  45. auto array_of_arrays = cpptoml::make_array();
  46. array_of_arrays->push_back(int_array);
  47. array_of_arrays->push_back(double_array);
  48. array_of_arrays->push_back(string_array);
  49. root->insert("ArrayOfArrays", array_of_arrays);
  50. std::cout << (*root);
  51. return 0;
  52. }