Reputation: 8951
I want to create a method which return a token and increment this one.
I did this:
_tokens is an std::istream_iterator
std::string getToken()
{
std::string result;
result = *_tokens;
++_tokens;
return result;
}
As you can see this is kinda ugly cause I am returning a copy of a copy.
But I cannot return a reference on result cause result is a local variable.
And I cannot get the reference on *_tokens cause ++_tokens will change the content.
Have you got any idea how I could do this in a better way ?
Upvotes: 0
Views: 48
Reputation: 310950
I think you mean the following
std::string getToken()
{
return *_tokens++;
}
Upvotes: 3