M
Markus Dehmann
I am wondering what is the "best" code to print out the elements of a
vector.
Assume they contain strings.
With "best", I mean shortest and most readable at the same time.
Of course, a for loop can be done. But I guess one can do it more
elegantly.
Something like this would be possible:
copy(v.begin(), v.end(), ostream_iterator<string>(cout, "\n"));
But I don't like it: The line begins with "copy", and that's
confusing. It has a kind of misleading semantics.
Then better with for_each. How would that look like? Or is there a
better version?
I wonder why there is no to_string(const string& delimiter) function
in vector. Then, we could write:
cout << v.to_string("\n") << endl;
Markus
vector.
Assume they contain strings.
With "best", I mean shortest and most readable at the same time.
Of course, a for loop can be done. But I guess one can do it more
elegantly.
Something like this would be possible:
copy(v.begin(), v.end(), ostream_iterator<string>(cout, "\n"));
But I don't like it: The line begins with "copy", and that's
confusing. It has a kind of misleading semantics.
Then better with for_each. How would that look like? Or is there a
better version?
I wonder why there is no to_string(const string& delimiter) function
in vector. Then, we could write:
cout << v.to_string("\n") << endl;
Markus