Inexplicable Compilation Error: Boost's String Split function

Discussion in 'C++' started by Saqib Ali, Oct 22, 2011.

  1. Saqib Ali

    Saqib Ali Guest

    I'm using Solaris: 5.10
    My Compiler is: /opt/solstudio12.2/bin/CC

    My stupidly simple C++ sample that uses Boost.

    #include <boost/algorithm/string.hpp> //
    Line 1
    #include <boost/algorithm/string/trim.hpp> //Line
    2
    #include <boost/algorithm/string/split.hpp> //Line
    3
    //
    Line 4
    using namespace
    std; //Line 5
    using namespace
    boost; //Line 6


    int
    main(void) //
    Line 9
    { //
    Line 10
    std::string str1(" hello world!
    "); //Line 11
    string tokens,
    allLines; //Line 12
    to_upper(str1); // str1 == " HELLO WORLD! " //Line 13
    trim(str1); // str1 == "HELLO WORLD!" //Line
    14
    split(tokens, allLines,
    is_any_of(":")); //Line 15
    //
    Line 16
    return
    -1; //
    Line 17

    }


    But no matter what I do, I keep getting the same compilation error.
    (See below).

    Can anyone explain how to make it go away? Does it work on your
    systems?


    % /opt/solstudio12.2/bin/CC -c myTest.C -I /vobs/zodiac/ADAT_base/
    BOOST/include -o myTest.o
    "/vobs/zodiac/ADAT_base/BOOST/include/boost/range/distance.hpp", line
    29: Error: Could not find a match for
    std::distance<std::_ForwardIterator, std::_Distance>(const char*,
    const char*) needed in boost::distance<boost::iterator_range<const
    char*>>(const boost::iterator_range<const char*>&).
    "/vobs/zodiac/ADAT_base/BOOST/include/boost/algorithm/string/detail/
    classification.hpp", line 85: Where: While instantiating
    "boost::distance<boost::iterator_range<const char*>>(const
    boost::iterator_range<const char*>&)".
    "/vobs/zodiac/ADAT_base/BOOST/include/boost/algorithm/string/detail/
    classification.hpp", line 85: Where: Instantiated from
    boost::algorithm::detail::is_any_ofF<char>::is_any_ofF<boost::iterator_range<const
    char*>>(const boost::iterator_range<const char*>&).
    "/vobs/zodiac/ADAT_base/BOOST/include/boost/algorithm/string/
    classification.hpp", line 207: Where: Instantiated from
    boost::algorithm::is_any_of<char[2]>(const char(&)[2]).
    "myTest.C", line 15: Where: Instantiated from non-template code.
    1 Error(s) detected.
    Saqib Ali, Oct 22, 2011
    #1
    1. Advertising

  2. Hello!

    On 22.10.2011 9:47, Saqib Ali wrote:

    > int
    > main(void) //Line 9
    > { //Line 10
    > std::string str1(" hello world! "); //Line 11
    > string tokens, allLines; //Line 12
    > to_upper(str1); // str1 == " HELLO WORLD! " //Line 13
    > trim(str1); // str1 == "HELLO WORLD!" //Line 14
    > split(tokens, allLines, is_any_of(":")); //Line 15


    According to Boost documentation, split puts its results into some
    container.
    So compilation error will go away if you declare tokens as
    std::vector<string> like this:

    std::vector<string> tokens;
    string allLines;

    But, as allLines is an empty string, split will produce empty tokens vector.

    Regards,
    Vyacheslav
    Vyacheslav Lanovets, Oct 22, 2011
    #2
    1. Advertising

  3. Saqib Ali

    Marc Guest

    Saqib Ali wrote:

    > I'm using Solaris: 5.10
    > My Compiler is: /opt/solstudio12.2/bin/CC

    [...]
    > % /opt/solstudio12.2/bin/CC -c myTest.C -I /vobs/zodiac/ADAT_base/
    > BOOST/include -o myTest.o


    The documentation of your compiler says that boost won't work unless
    you use -library=stlport4 (or -library=stdcxx4). And even with those
    options, not everything works.
    Marc, Oct 22, 2011
    #3
  4. Saqib Ali

    Saqib Ali Guest

    >
    > std::vector<string> tokens;
    > string allLines;
    >
    > But, as allLines is an empty string, split will produce empty tokens vector.
    >
    > Regards,
    > Vyacheslav


    I simplified my program to look like this:


    #include <boost/algorithm/string.hpp>
    #include <boost/algorithm/string/trim.hpp>
    #include <boost/algorithm/string/split.hpp>
    #include <vector>


    using namespace std;
    using namespace boost;


    int main(void)
    {
    vector <string> tokens;
    string allLines = "X:Y:Z";
    split(tokens, allLines, is_any_of(":"));

    for (int i = 0; i <= tokens.size()-1; i++)
    cout << tokens << endl;

    return 1;

    }


    It still gives me the same error on the call to split()
    Saqib Ali, Oct 23, 2011
    #4
  5. Saqib Ali

    Saqib Ali Guest


    > The documentation of your compiler says that boost won't work unless
    > you use -library=stlport4 (or -library=stdcxx4). And even with those
    > options, not everything works.


    Thanks!!

    -library=stlport4 made it work!
    Saqib Ali, Oct 23, 2011
    #5
  6. Saqib Ali <> wrote:
    > using namespace std;
    > using namespace boost;


    I hope you understand that you are risking name collisions by doing that.
    Juha Nieminen, Oct 23, 2011
    #6
  7. Hello!

    On 23.10.2011 10:34, Saqib Ali wrote:
    >
    > I simplified my program to look like this:
    >
    >
    > #include<boost/algorithm/string.hpp>
    > #include<boost/algorithm/string/trim.hpp>
    > #include<boost/algorithm/string/split.hpp>
    > #include<vector>


    The code is almost correct - only #include <iostream> is missing (for cout).

    But if the error is the same, then it does not like is_any_of.
    Could you check if the following code compile?

    #include <boost/algorithm/string.hpp>
    int main(void)
    {
    boost::is_any_of(":");

    return 1;
    }

    Regards,
    Vyacheslav
    Vyacheslav Lanovets, Oct 24, 2011
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Dave
    Replies:
    13
    Views:
    745
    Cy Edmunds
    Jan 1, 2004
  2. Fabiano Sidler

    Inexplicable behaviour of <type 'function'>

    Fabiano Sidler, Apr 23, 2006, in forum: Python
    Replies:
    1
    Views:
    283
    Leif K-Brooks
    Apr 23, 2006
  3. Replies:
    2
    Views:
    534
  4. =?ISO-8859-1?Q?Martin_J=F8rgensen?=
    Replies:
    5
    Views:
    1,294
    =?ISO-8859-1?Q?Martin_J=F8rgensen?=
    May 6, 2006
  5. Sam Kong
    Replies:
    5
    Views:
    238
    Rick DeNatale
    Aug 12, 2006
Loading...

Share This Page