Re: Problem using std::prev on ustring iterator



On 18 March 2016 at 17:57, jeremy.harmon wrote:
Hello,

When I try to use std::prev on a ustring const_iterator nothing
happens, operator-- works fine.

Glib::ustring str = "test";
Glib::ustring::iterator iter = str.begin();

std::advance(iter);
printf("%c\n", *iter);

std::prev(iter);
printf("%c\n", *iter);

iter--;
printf("%c\n", *iter);

Output is
e
e
t

Any ideas why it doesn't work?

Because unlike std::advance, std::prev doesn't modify its argument, it
returns the new iterator instead.

http://en.cppreference.com/w/cpp/iterator/prev


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]