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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:21:37+00:00 2026-05-23T11:21:37+00:00

I am learning Boost Spirit and simply modified an example given in the documentation

  • 0

I am learning Boost Spirit and simply modified an example given in the documentation to match strings instead of doubles. But the code doesn’t compile and I get errors which I am unable to debug. Below is the code and the printed errors. Can you please help me debug this problem ?

PS: I am guessing the problem lies in using phoenix::ref for vector string, but not exactly sure how and why.

#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_stl.hpp>
#include <boost/config/warning_disable.hpp>

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

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

    template <typename Iterator>

    bool parse_data(Iterator first, Iterator last, std::vector<std::string>& v)
    {
        using qi::double_;
        using qi::char_;
        using qi::phrase_parse;
        using qi::_1;
        using ascii::space;
        using phoenix::ref;
        using phoenix::push_back;

        bool r = phrase_parse(
            first,
            last,
            +(char_)[push_back(ref(v), _1)],        
            char_('/')  
        );
        if (first != last)
            return false;
        return r;
    }
}

int 
main()
{
    std::string str;

    while (getline(std::cin, str))
    {
        if (str.empty())
            break;

        std::vector<std::string> v;
        if(client::parse_data(str.begin(), str.end(), v))
        {
            std::cout << std::endl << "Parsing done" << std::endl;
            std::cout << "Numbers are " ;
            for(std::vector<std::string>::iterator i = v.begin(); i < v.end(); i++)
            {
                std::cout << *i <<" ";
            }
            std::cout << std::endl;
        }
        else
        {
            std::cout << "Parsing Failed" << std::endl;
        }
    }

    return 0;
}

This is the error I get:

/usr/local/include/boost_1_46_1/boost/spirit/home/phoenix/stl/container/container.hpp:492:
error: invalid conversion from ‘const char’ to ‘const char*’

/usr/local/include/boost_1_46_1/boost/spirit/home/phoenix/stl/container/container.hpp:492: 
error:   initializing argument 1 of ‘std::basic_string<_CharT, _Traits, _Alloc>::basic_string(const _CharT*, const _Alloc&) [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>]’
  • 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-23T11:21:38+00:00Added an answer on May 23, 2026 at 11:21 am

    If you write it as

    bool r = phrase_parse(
        first, last, +(char_[push_back(ref(v), _1)]), char_('/')  
    );
    

    it will work. But writing

    bool r = phrase_parse(
        first, last, +char_, '/', v
    );
    

    is even simpler (and runs faster).

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

Sidebar

Related Questions

I am learning boost/asio and writing example program which was in e-book. of course
I'm learning the use of boost smart pointers but I'm a bit confused about
I am learning the boost::lambda library and for that I wrote this sample code
I'm learning boost and I wanted to rewrite my Matrix class. Instead of for
So I've been learning a bit about Boost.Spirit to replace the use of regular
Learning boost, and compiled their daytime server client example . Since I cant use
I am learning boost/asio ad wrote 2 programs(client and server) from e-book with minor
I am learning how to use the boost asio libraries and I am using
I've been playing around with boost threads today as a learning exercise, and I've
These days I am starting learning BOOST UBLAS and BOOST MATH for my tasks.

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.