Inexplicable Compilation Error: Boost's String Split function

S

Saqib Ali

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.
 
V

Vyacheslav Lanovets

Hello!

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
 
M

Marc

Saqib said:
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.
 
S

Saqib Ali

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()
 
S

Saqib Ali

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!
 
V

Vyacheslav Lanovets

Hello!

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,533
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top