You're looking at it! Browse the docs using the links at the top of the page. You can search from anywhere by pressing the TAB key.

Parsing files Call toml:: parse_file() and work with the toml:: table you get back, or handle any toml:: parse_error that gets thrown: #include <iostream> #include <fstream> //required for parse_file() #include <toml++/toml.h> int main ( int argc , char ** argv ) { toml:: table tbl ; try { tbl = toml:: parse_file ( argv [ 1 ]); std:: cout << tbl << "

" ; } catch ( const toml:: parse_error & err ) { std:: cerr << "Parsing failed:

" << err << "

" ; return 1 ; } return 0 ; } Don't forget #include <fstream> ! Not everyone who uses the library is going to work directly from files, so not everybody is forced to pay the compilation overhead of including <fstream> . You need to explicitly include it if you're going to be calling toml:: parse_file(). See also toml:: parse_file()



parse_file() toml:: table



table toml:: parse_error

Handling errors without exceptions Can't (or won't) use exceptions? That's fine too. You can disable exceptions in your compiler flags and/or explicitly disable the library's use of them by setting the option TOML_ EXCEPTIONS to 0 . In either case, the parsing functions return a toml:: parse_result instead of a toml:: table: #include <iostream> #include <fstream> #define TOML_EXCEPTIONS 0 // only necessary if you've left them enabled in your compiler #include <toml++/toml.h> int main () { toml:: parse_result result = toml:: parse_file ( "configuration.toml" ); if ( ! result ) { std:: cerr << "Parsing failed:

" << result . error () << "

" ; return 1 ; } do_stuff_with_your_config ( std:: move ( result ). table ()); // 'steal' the table from the result return 0 ; }

Custom error formatting The examples above use an overloaded operator<< with ostreams to print basic error messages, and look like this: Error while parsing key: expected bare key starting character or string delimiter, saw '?' (error occurred at line 2, column 5) In order to keep the library as small as possible I haven't bent over backwards to support things like custom colouring of the text in TTY environments, et cetera. That being said, the library provides the requisite information for you to build these yourself if necessary via toml:: parse_error's source() and description() members: toml:: table tbl ; try { tbl = toml:: parse_file ( "configuration.toml" ); } catch ( const toml:: parse_error & err ) { std:: cerr << "Error parsing file '" << * err . source (). path << "':

" << err . description () << "

(" << err . source (). begin << ")

" ; return 1 ; } See also toml:: parse_error



parse_error toml:: source_region



source_region toml:: source_position

Serializing as TOML and JSON All toml++ data types have overloaded operator<< for ostreams, so 'serializing' a set of TOML data to actual TOML is done just by printing it to an ostream. Converting it to JSON is done in the same way, but via a toml:: json_formatter. Try this code on Compiler Explorer #include <iostream> #include <toml++/toml.h> int main () { auto tbl = toml:: table {{ { "lib" , "toml++" }, { "cpp" , toml:: array { 17 , 20 , "and beyond" } }, { "toml" , toml:: array { "1.0.0-rc.2" , "and beyond" } }, { "repo" , "https://github.com/marzer/tomlplusplus/" }, { "author" , toml:: table {{ { "name" , "Mark Gillard" }, { "github" , "https://github.com/marzer" }, { "twitter" , "https://twitter.com/marzer8789" } }} }, }}; // serializing as TOML std:: cout << "###### TOML ######" << "



" ; std:: cout << tbl << "



" ; // serializing as JSON using toml::json_formatter: std:: cout << "###### JSON ######" << "



" ; std:: cout << toml:: json_formatter { tbl } << "



" ; return 0 ; } # ##### TOML ###### cpp = [ 17, 20, 'and beyond' ] lib = 'toml++' repo = 'https://github.com/marzer/tomlplusplus/' toml = [ '1.0.0-rc.2', 'and beyond' ] [author] github = 'https://github.com/marzer' name = 'Mark Gillard' twitter = 'https://twitter.com/marzer8789' # ##### JSON ###### { "author" : { "github" : "https://github.com/marzer", "name" : "Mark Gillard", "twitter" : "https://twitter.com/marzer8789" }, "cpp" : [ 17, 20, "and beyond" ], "lib" : "toml++", "repo" : "https://github.com/marzer/tomlplusplus/", "toml" : [ "1.0.0-rc.2", "and beyond" ] } See also toml:: default_formatter

default_formatter toml:: json_formatter