I've got a line of code but not sure how part of it actually work's.

for (auto i = text.begin(); i != text.end() && !i->empty(); ++i)

How does the !i->empty() statement work? Is it the same as: !text.empty()

Can someone can explain the use of ->

Searching for somthing like that yield's wierd result's in a search engine.
closed account (S6k9GNh0)
This is why the use of auto is questioned...

i is (most likely) an iterator. This iterator appears to be assocated with a string. The -> directive allows you to "dereference" the iterator and then fetch a member. An iterator "acts" as a dummy pointer (when in actuality, it just wraps around one most of the time) which is why the syntax is like this.

empty() checks for whether or not the string is empty... doesn't really make sense for it to be checked each iteration since the iterators would become invalid after the string changes anyways.
Last edited on
Thank's computerquip.
Topic archived. No new replies allowed.