[tokenizer] mutable string iterator

Hi there, I would like to use the tokenizer to iterate through a string of words and reverse them. Something like this: string str( " Hello World" ); tokenizer<> tok(str); for(tokenizer<>::iterator beg=tok.begin(); beg!=tok.end();++beg) { reverse( (*beg).begin(), (*beg).end() ); } Why can't I get a mutable string iterator? Thanks, Christian

Hi, You may try to use tokenization facilities in string_algo library. They have no such a limitation. You can tokenize with mutable iterators. Regards, Pavol. Christian Henning wrote:
Hi there, I would like to use the tokenizer to iterate through a string of words and reverse them. Something like this:
string str( " Hello World" );
tokenizer<> tok(str); for(tokenizer<>::iterator beg=tok.begin(); beg!=tok.end();++beg) { reverse( (*beg).begin(), (*beg).end() ); }
Why can't I get a mutable string iterator?
Thanks, Christian _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

Thanks Pavol,
I was able to get my problem solved by using the split algorithm:
void reverse_word( iterator_range< string::iterator >& range )
{
reverse( range.begin(), range.end() );
}
int _tmain(int argc, _TCHAR* argv[])
{
string str( " Hello World" );
typedef vector< iterator_range< string::iterator > > find_vector_type;
find_vector_type vec;
split( vec, str, is_any_of(" ") );
for_each( vec.begin(), vec.end(), reverse_word );
cout << str << endl;
return 0;
}
But is there a way to use the split iterator? I wasn't able to create
one for my problem.
Thanks,
Christian
On Sat, Mar 15, 2008 at 4:15 PM, Pavol Droba
Hi,
You may try to use tokenization facilities in string_algo library. They have no such a limitation. You can tokenize with mutable iterators.
Regards, Pavol.
Christian Henning wrote:
Hi there, I would like to use the tokenizer to iterate through a string of words and reverse them. Something like this:
string str( " Hello World" );
tokenizer<> tok(str); for(tokenizer<>::iterator beg=tok.begin(); beg!=tok.end();++beg) { reverse( (*beg).begin(), (*beg).end() ); }
Why can't I get a mutable string iterator?
Thanks, Christian _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

Hi Christian, This should do the trick: typedef split_iteratorstring::iterator string_split_iterator; for(string_split_iterator It= make_split_iterator(str, token_finder(is_space(), token_compress_on); It!=string_split_iterator(); ++It) { reverse_word(*it) } Regards, Pavol Christian Henning wrote:
Thanks Pavol,
I was able to get my problem solved by using the split algorithm:
void reverse_word( iterator_range< string::iterator >& range ) { reverse( range.begin(), range.end() ); }
int _tmain(int argc, _TCHAR* argv[]) { string str( " Hello World" );
typedef vector< iterator_range< string::iterator > > find_vector_type; find_vector_type vec; split( vec, str, is_any_of(" ") );
for_each( vec.begin(), vec.end(), reverse_word );
cout << str << endl;
return 0; }
But is there a way to use the split iterator? I wasn't able to create one for my problem.
Thanks, Christian
On Sat, Mar 15, 2008 at 4:15 PM, Pavol Droba
wrote: Hi,
You may try to use tokenization facilities in string_algo library. They have no such a limitation. You can tokenize with mutable iterators.
Regards, Pavol.
Christian Henning wrote:
Hi there, I would like to use the tokenizer to iterate through a string of words and reverse them. Something like this:
string str( " Hello World" );
tokenizer<> tok(str); for(tokenizer<>::iterator beg=tok.begin(); beg!=tok.end();++beg) { reverse( (*beg).begin(), (*beg).end() ); }
Why can't I get a mutable string iterator?
Thanks, Christian _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
participants (2)
-
Christian Henning
-
Pavol Droba