| 1 |
|
|---|
| 2 | #include <iostream>
|
|---|
| 3 | #include <string>
|
|---|
| 4 |
|
|---|
| 5 | #include <boost/spirit/include/qi_parse.hpp>
|
|---|
| 6 | #include <boost/spirit/include/qi_numeric.hpp>
|
|---|
| 7 |
|
|---|
| 8 | void Str2Int(const std::string& str)
|
|---|
| 9 | {
|
|---|
| 10 | int result;
|
|---|
| 11 | std::cout << "Parsing '" << str << "':\n";
|
|---|
| 12 |
|
|---|
| 13 | std::string::const_iterator i = str.begin();
|
|---|
| 14 | if (!boost::spirit::qi::parse(i, str.end(), boost::spirit::int_, result)){
|
|---|
| 15 | std::cout << " parse failed\n";
|
|---|
| 16 | return;
|
|---|
| 17 | } else {
|
|---|
| 18 | std::cout << " parse success " << result << "\n";
|
|---|
| 19 | }
|
|---|
| 20 | if( i != str.end() )
|
|---|
| 21 | std::cout << " have leftovers\n";
|
|---|
| 22 | }
|
|---|
| 23 |
|
|---|
| 24 | int main(){
|
|---|
| 25 | std::cout << "sizeof(int): " << sizeof(int) << "\n";
|
|---|
| 26 |
|
|---|
| 27 | Str2Int( "2147483647" );
|
|---|
| 28 | Str2Int( "2147483648" );
|
|---|
| 29 |
|
|---|
| 30 | return 0;
|
|---|
| 31 | }
|
|---|