* Tong * wrote:
Quote:
Hi,
>
Simple question, how to get a reverse_iterator?
>
As you can see from the following code, I managed to answer the first half
of the question myself, but can't figure out the second half:
>
string line("FIRST,MIDDLE,LAST");
>
// find first element in a comma-separated list
string::iterator comma = find(line.begin(), line.end(), ',');
cout << string(line.begin(), comma) << endl;
>
cout << string(++comma, line.end()) << endl;
>
// get reverse_iterator from iterator
string::reverse_iterator commar = string::reverse_iterator(comma);
cout << string(line.rbegin(), commar) << endl;
>
// get reverse_iterator from reverse_iterator. wrong. how to fix?
cout << string(++comma, string::reverse_iterator(line.rbegin())) << endl;
>
It's not the initialising of the iterator that's the problem, it's the
attempt to construct a string from an iterator and a reverse_iterator.
--
Ian Collins.