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 6107931
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:14:32+00:00 2026-05-23T14:14:32+00:00

I have the following code can not compile, however I do not know where

  • 0

I have the following code can not compile, however I do not know where is the problem:

#include <boost/config/warning_disable.hpp>
#include <boost/spirit/include/qi.hpp>
#include <boost/spirit/include/phoenix_core.hpp>
#include <boost/spirit/include/phoenix_operator.hpp>
#include <boost/spirit/include/phoenix_fusion.hpp>
#include <boost/spirit/include/phoenix_stl.hpp>
#include <boost/fusion/include/adapt_struct.hpp>
#include <boost/variant/recursive_variant.hpp>
#include <boost/foreach.hpp>

#include <iostream>
#include <fstream>
#include <string>
#include <vector>

void print (std::string& s)
{
    std::cout << "Get string [" << s << ']' << std::endl;
}

namespace client
{
    namespace fusion = boost::fusion;
    namespace phoenix = boost::phoenix;
    namespace qi = boost::spirit::qi;
    namespace ascii = boost::spirit::ascii;

    template <typename Iterator>
    struct my_grammar
      : qi::grammar<Iterator, std::string(), ascii::space_type>
    {
        my_grammar()
          : my_grammar::base_type(start)
        {
        using qi::lit;
        using qi::int_;
        using qi::lexeme;
        using ascii::char_;
        using ascii::string;
        using ascii::space_type;
        using namespace qi::labels;


        // Here you can see the rule oct_char with attribute type as char
        // +(char) would be vector<char> which is compactable with string type
        // Why the compiler still told me the type of the attribute is not right?
        start %= lexeme[+(oct_char)] [&print]
            ;

        oct_char =
                   lexeme["//"        
                           >>  char_('0','3') [ _a = ( _1 - '0' ) ]
                     ||     char_('0','7') [ _a = _a << 3 + ( _1 - '0' ) ]
                ||     char_('0','7') [ _a = _a << 3 + ( _1 - '0' ) ]]
                 [ _val = _a ]
                ;
        }
    qi::rule<Iterator, std::string(), ascii::space_type> start;
        qi::rule<Iterator, char(), qi::locals<char>, ascii::space_type> oct_char;

    };
}

int main(int argc, char **argv)
{

    typedef client::my_grammar<std::string::const_iterator> Grammer;
    Grammer grm;

    std::string str;


using boost::spirit::ascii::space;

while (getline(std::cin, str))
{
    if (str.empty() || str[0] == 'q' || str[0] == 'Q')
        break;

    if (phrase_parse(str.begin(), str.end(), grm, space))
    {
        std::cout << "-------------------------\n";
        std::cout << "Parsing succeeded\n";
        std::cout << "got: " << str << std::endl;
        std::cout << "\n-------------------------\n";
    }
    else
    {
        std::cout << "-------------------------\n";
        std::cout << "Parsing failed\n";
        std::cout << "-------------------------\n";
    }
}

std::cout << "Bye... :-) \n\n";
return 0;


}

Here are the error messages:

Error   2   error C2664: 'void (std::basic_string<_Elem,_Traits,_Ax> )' : cannot convert parameter 1 from 'std::vector<_Ty>' to 'std::basic_string<_Elem,_Traits,_Ax> ' d:\code\boost_1_46_1\boost\spirit\home\support\action_dispatch.hpp  70

Is there anyone can give some suggestions?
Thanks

  • 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-05-23T14:14:32+00:00Added an answer on May 23, 2026 at 2:14 pm

    This has been discussed at length elsewhere (for instance here). If you change your print function to take a vector<char> it will work:

    void print (std::vector<char> const& s)
    {
        std::cout << "Get string [" 
                  << std::string(s.begin(), s.end()) << ']' 
                  << std::endl;
    }
    

    There is one more error in your code, though. The rule oct_char does not need to have a skipper as it is used inside lexeme[]:

    qi::rule<Iterator, char(), qi::locals<char> > oct_char;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code and I can't understand what does it mean: var1
i have written the following code: As you can see there is a for
I have the following code to do this, but how can I do it
Please can someone help? I have the following code which uploads a file to
I have a simple 3D cube that I can rotate using the following code:
According to what I have found so far, I can use the following code:
Following on from this question I now have code that can attach to a
We have similar code to the following in one of our projects. Can anyone
I have the following code. #include <set> #include <algorithm> using namespace std; int _tmain(int
I have the following code in html, I cannot get the Function call back

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.