Assuming that iter is a vector<string>::iterator, indicate which, if any, of the following expressions are legal
belongs to book: C++ Primer|Stanley B.Lippman, Josee Lajoie, Barbara E.Moo|5th Edition| Chapter number:4| Question number:4.20
All Answers
total answers (1)
(a) `*iter++;` is legal. The expression moves `iter` to point to the next element and returns the value of the original element.
(b) `(*iter)++` is not legal. The expression means increasing value of the element, but the value is a `string` and `string` does not have `++` operator.
(c) `*iter.empty()` is not legal. Because `iter` is an iterator and has no member named `empty`.
(d) `iter->empty()` is legal. The expression means check if the string pointed by `iter` is empty.
(e) `++*iter` is not legal. The expression means increasing value of the element, but the value is a `string` and `string` does not have `++` operator.
(f) `iter++->empty()` is legal. The expression means move `iter` to point to the next element and check if the original `string` is empty.
need an explanation for this answer? contact us directly to get an explanation for this answer