On 2/20/07, Pavol Droba
Hi,
Meryl Silverburgh wrote:
On 2/19/07, Pavol Droba
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_iteratorstring::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
r1( make_split_iterator(s1, is_any_of("/")), string_split()); iterator_range
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
for lexicographical_compare. With these modification, I have tried and compiled the code successfully.
Thanks for your help again. However, I still have compilation error.
It still does not like make_split_iterator:
g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"stringCompare.d"
-MT"stringCompare.d" -o"stringCompare.o" "../stringCompare.cpp"
../stringCompare.cpp:44:2: warning: no newline at end of file
../stringCompare.cpp: In function 'int main(int, char**)':
../stringCompare.cpp:29: error: no matching function for call to
'make_split_iterator(std::string&,
boost::algorithm::detail::token_finderF , string_split)'
../stringCompare.cpp:32: error: no matching function for call to
'make_split_iterator(std::string&,
boost::algorithm::detail::token_finderF #include <iostream>
#include <string>
#include "boost/algorithm/string/find_iterator.hpp"
#include "boost/algorithm/string/classification.hpp"
#include "boost/algorithm/string/predicate.hpp"
using namespace std;
using namespace boost;
typedef split_iteratorstring::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 Best Regards,
Pavol.
_______________________________________________
Boost-users mailing list
Boost-users@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users