Function parse_file
Synopsis
#include <include/cpptoml.h>
std::shared_ptr< table > parse_file(const std::string &filename)
Description
Utility function to parse a file as a TOML file. Returns the root table. Throws a parse_exception if the file cannot be opened.
Mentioned in
- Getting Started / Example Usage
- Getting Started / Nested Tables
- Getting Started / Arrays of Values
- Getting Started / Arrays of Tables
Source
Lines 3219-3232 in include/cpptoml.h.
inline std::shared_ptr<table> parse_file(const std::string& filename)
{
#if defined(BOOST_NOWIDE_FSTREAM_INCLUDED_HPP)
boost::nowide::ifstream file{filename.c_str()};
#elif defined(NOWIDE_FSTREAM_INCLUDED_HPP)
nowide::ifstream file{filename.c_str()};
#else
std::ifstream file{filename};
#endif
if (!file.is_open())
throw parse_exception{filename + " could not be opened for parsing"};
parser p{file};
return p.parse();
}