Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Since parsing toml from file must be a common use-case, parseFile would be useful for a casual user. BUG=#32
- Loading branch information
Showing
4 changed files
with
41 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#include "toml/toml.h" | ||
|
||
#include <fstream> | ||
#include <iostream> | ||
|
||
using namespace std; | ||
|
||
int main(int argc, char* argv[]) | ||
{ | ||
if (argc < 2) { | ||
cerr << "Usage:" << endl | ||
<< " " << argv[0] << " <input-file>" << endl; | ||
return 1; | ||
} | ||
|
||
ifstream ifs(argv[1]); | ||
// Pass ifs without checking error (to test toml::parse detects and error). | ||
// In usual case, I recommend to check ifs state. | ||
toml::ParseResult pr = toml::parse(ifs); | ||
if (pr.valid()) { | ||
cout << pr.value; | ||
} else { | ||
cout << pr.errorReason << endl; | ||
} | ||
} |