Boost logo

Boost Users :

From: Pavol Droba (droba_at_[hidden])
Date: 2007-02-20 02:28:22


Hi,

Meryl Silverburgh wrote:
> On 2/19/07, Pavol Droba <droba_at_[hidden]> wrote:
<snip>

>
> Thanks for your help. I am getting the following error.
> I haven't implemented integer_compare(), but I still can't get what I
> have to compile:
>
> Build complete for project str
>
> #include <iostream>
> #include <string>
>
> #include "boost/algorithm/string/find_iterator.hpp"
> #include "boost/algorithm/string/classification.hpp"
> using namespace std;
> using namespace boost::algorithm;
>
> typedef split_iterator<string::iterator> string_split;
>
> class integer_compare {
> public:
> bool operator() (const string_split::value_type &a, const
> string_split::value_type &b) {
> return true;
> }
> };
>
> int main(int argc, char **argv) {
> cout << "hello world" << endl;
>
> string s1("/1/11/2");
> string s2("/1/1/3");
>
> iterator_range<string_split> r1(
> make_split_iterator(s1, is_any_of("/")), string_split());
>
> iterator_range<string_split> r2(
> make_split_iterator(s2, is_any_of("/")), string_split());
>
> if(lexicographical_compare(r1.begin(), r1.end(),
>
> r2.begin(), r2.end(), integer_compare()))
> {
> cout << " s1 is less " << endl;
> } else {
> cout << " s2 is less " << endl;
> }
>
>
> }

So I forgot something else again. Shame on me. In the
make_split_iterator call you have to specify a finder. I somehow forgot
this. So the correct syntax is:
make_split_iterator(s1, token_finder(is_any_of("/"))

In addition there is a problem in using directives. I suggest you don't
use using namespace boost::algorithms, but rather using namespace boost;
In the current state, iterator_range is not available since it is in the
namespace boost. It is actualy defined in boost.range library in in the
string algorithms itself.
All relevant string algorithms are pulled to namespace boost as well.

Also, add another include
#include <boost/algorithm/string/predicate.hpp> for lexicographical_compare.

With these modification, I have tried and compiled the code successfully.

Best Regards,
Pavol.


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net