Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9166803
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T15:14:14+00:00 2026-06-17T15:14:14+00:00

I want to parse a floating point number in a text file and insert

  • 0

I want to parse a floating point number in a text file and insert it in a symbol table; the parser and the symbol table are provided by spirit::qi.

Here is my code:

#include <boost/spirit/include/qi.hpp>
#include <boost/spirit/include/phoenix.hpp>

#include <stdint.h>
#include <iostream>
#include <string>
template<typename VTYPE>
struct VTable : boost::spirit::qi::symbols<char, VTYPE> {
    VTable() {} // empty
};

int main() {
using boost::spirit::qi::_1;
using boost::spirit::qi::eps;
using boost::spirit::qi::rule;
using boost::spirit::qi::ascii::space;
using boost::spirit::qi::space_type;
using boost::spirit::qi::real_parser;
using boost::spirit::qi::int_parser;
using boost::spirit::qi::strict_real_policies;
    VTable<double> floatDecs;
    floatDecs.add("hallo", 15.26)("duDa", 18.5);

const std::string some = "some";
    rule<std::string::iterator, double> value = real_parser<double, strict_real_policies<double>>() [ boost::phoenix::bind(&VTable<double>::add, floatDecs, boost::phoenix::cref(some), _1) ];

    std::cout << boost::spirit::qi::phrase_parse(test.begin(), test.end(), value, space);
    return 0;
}

The problem in here lies in boost::phoenix::bind, but I do not know, how to fix that (I am fairly new to this library).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T15:14:15+00:00Added an answer on June 17, 2026 at 3:14 pm

    Here’s a working version. After, I’ll list what was wrong with yours.

    #include <boost/spirit/include/qi.hpp>
    #include <boost/spirit/include/phoenix.hpp>
    
    #include <stdint.h>
    #include <iostream>
    #include <string>
    template<typename VTYPE>
    struct VTable : boost::spirit::qi::symbols<char, VTYPE> {
        VTable() {} // empty
    };
    
    int main() {
    using boost::spirit::qi::_1;
    using boost::spirit::qi::eps;
    using boost::spirit::qi::rule;
    using boost::spirit::qi::ascii::space;
    using boost::spirit::qi::space_type;
    using boost::spirit::qi::real_parser;
    using boost::spirit::qi::int_parser;
    using boost::spirit::qi::strict_real_policies;
    
        VTable<double> floatDecs;
        floatDecs.add("hallo", 15.26)("duDa", 18.5);
    
        const char some[] = "some";
    
        rule<std::string::iterator, double()> value =
                real_parser<double, strict_real_policies<double> >()
                [ boost::phoenix::bind(floatDecs.add, boost::phoenix::val(some), _1) ];
    
        std::string test("10.6");
    
        std::string::iterator b(test.begin()), e(test.end());
    
        std::cout << boost::spirit::qi::phrase_parse(b, e, value, space);
    
        return 0;
    }
    

    First, the variable you want to use as an argument to add() needs to be fixed.

    const char some[] = "some";
    

    Next, you need to fix the syntax in your rule template parameters:

    rule<std::string::iterator, double()>
    

    Note the brackets, to make the double a functor declaration rather than a vanilla double, for lazy evaluation.

    Next, you need to use the syntax above for your semantic action.

    [ boost::phoenix::bind(floatDecs.add, boost::phoenix::val(some), _1) ];
    

    Honestly I am not sure why this works as I am not a phoenix expert, but the link in ‘sehe’s’ comment above provided the answer. Also, you were barking up the wrong tree with cref, there’s no indication from add()‘s declaration that a reference is what’s required. val is what you need to turn the some variable into a phoenix-happy lazy argument.

    Finally, you just need to supply some reasonable test data.

    The code above should work for you now.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to parse the xml file with dynamic content using DOM parser in
What is the best way to parse a large floating point file stored in
How do I convert a string to a floating point number if I want
I want to parse an XML file using SAX parser in java with this
I want to parse two files. I have Yacc/lex code which generates the parser.
I want to parse xml file in utf-8 and sort it by some field.
I want to parse a xml file using xquery in Ruby, I found this
I want to parse atom feeds of youtube channel. Here is the link of
I have implemented ipad application in which i want parse table of content but
I want to parse a dtd file and use the info I get from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.