|
Boost Users : |
From: Alex Vinokur (alexvn_at_[hidden])
Date: 2005-12-30 09:17:52
Pavol Droba wrote:
> On Sat, Dec 24, 2005 at 09:06:51AM +0200, Alex Vinokur wrote:
> >
> > "Pavol Droba" <droba_at_[hidden]> wrote in message news:20051223180408.GP15407_at_lenin.felcer.sk...
> > > Hi,
> > >
> > > You might be able to do it using the string_algo find_iterator.
> > >
> > > #include <boost/algorithm/string.hpp>
> > >
> > > using namespace std;
> > > using namespace boost;
> > >
> > > ...
> > >
> > [snip]
> > typedef split_iterator<string::iterator> string_find_iterator;
> > ------------------------------------------------------------------------------
> > > string_find_iterator It=make_find_iterator(str1, token_finder(is_space()));
> >
> > That line produces the following error message:
> >
> > error: conversion from `boost::algorithm::find_iterator<__gnu_cxx::__normal_iterator<char*, std::basic_string<char,
> > std::char_traits<char>, std::allocator<char> > > >' to non-scalar type
> > `boost::algorithm::split_iterator<__gnu_cxx::__normal_iterator<char*, std::basic_string<char, std::char_traits<char>,
> > std::allocator<char> > > >' requested
> >
>
> Sorry, I have fixed one error, but the other line was tied to it.
> the second line should be
> string_find_iterator It=make_split_iterator(str1, token_finder(is_space()));
>
> Regards,
> Pavol
Thanks.
Here is what I compiled:
--------
#include<iostream>
#include<boost/tokenizer.hpp>
#include<boost/algorithm/string.hpp>
#include<string>
using namespace std;
using namespace boost;
void test()
{
string s = "ab cd \n xy z\n123";
typedef split_iterator<string::iterator> string_find_iterator;
string_find_iterator It = make_split_iterator(s, token_finder(is_space()));
const int maxi = 3;
const int maxj = 2;
for(int i=0; i < maxi; i++)
{
for(int j=0; j < maxj; j++)
{
if(It != string_find_iterator()) cout << "(" << i << ", " << j << ") : " << (*It) << endl;
else break;
}
}
}
int main ()
{
test();
return 0;
}
--------
And here is what I have got after running:
--- (0, 0) : ab (0, 1) : ab (1, 0) : ab (1, 1) : ab (2, 0) : ab (2, 1) : ab --- Alex Vinokur email: alex DOT vinokur AT gmail DOT com http://mathforum.org/library/view/10978.html http://sourceforge.net/users/alexvn
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