MCPcopy Create free account
hub / github.com/boostorg/parser / main

Function main

example/parsing_into_a_class.cpp:15–47  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

13namespace bp = boost::parser;
14
15int main()
16{
17 std::cout << "Enter a string followed by two unsigned integers. ";
18 std::string input;
19 std::getline(std::cin, input);
20
21 //[ parsing_into_a_class_str
22 constexpr auto string_uint_uint =
23 bp::lexeme[+(bp::char_ - ' ')] >> bp::uint_ >> bp::uint_;
24 std::string string_from_parse;
25 if (parse(input, string_uint_uint, bp::ws, string_from_parse))
26 std::cout << "That yields this string: " << string_from_parse << "\n";
27 else
28 std::cout << "Parse failure.\n";
29 //]
30
31 std::cout << "Enter an unsigned integer followed by a string. ";
32 std::getline(std::cin, input);
33 std::cout << input << "\n";
34
35 //[ parsing_into_a_class_vec_of_strs
36 constexpr auto uint_string = bp::uint_ >> +bp::char_;
37 std::vector<std::string> vector_from_parse;
38 if (parse(input, uint_string, bp::ws, vector_from_parse)) {
39 std::cout << "That yields this vector of strings:\n";
40 for (auto && str : vector_from_parse) {
41 std::cout << " '" << str << "'\n";
42 }
43 } else {
44 std::cout << "Parse failure.\n";
45 }
46 //]
47}
48//]

Callers

nothing calls this directly

Calls 1

parseFunction · 0.70

Tested by

no test coverage detected