Skip to content

Commit 7cd8fb0

Browse files
committed
Add a simple C++ example.
1 parent df400d1 commit 7cd8fb0

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

examples/ucl_cpp.cc

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#include <iostream>
2+
#include <string>
3+
#include "ucl++.h"
4+
5+
int main(int argc, char **argv)
6+
{
7+
std::string input, err;
8+
9+
input.assign((std::istreambuf_iterator<char>(std::cin)),
10+
std::istreambuf_iterator<char>());
11+
12+
auto obj = ucl::Ucl::parse(input, err);
13+
14+
if (obj) {
15+
std::cout << obj.dump(UCL_EMIT_CONFIG) << std::endl;
16+
17+
for (const auto &o : obj) {
18+
std::cout << o.dump(UCL_EMIT_CONFIG) << std::endl;
19+
}
20+
}
21+
else {
22+
std::cerr << "Error: " << err << std::endl;
23+
24+
return 1;
25+
}
26+
}

0 commit comments

Comments
 (0)