The postincrement (x++) syntax, in a loose way, means "give me the value of x, and once you have, increment x". The preincrement (++x) means "increment x, then give me the value".
In order to fulfill the requirements of the postincrement, the compiler basically does this:
temp = x;x = x + 1;// Do stuff with temp
When using an iterator (or any other object), this creates a hidden temporary object with the same value as the iterator. The result is that each time the iterator is incremented, there is a copy operation done as well to make the temporary value, which is wasteful. For certain types of objects, this copy can be a very expensive operation.
A preincrement does not preserve the old value, so it does not involve this copy overhead. This means that, in general, preincrement (and predecrement) operations are more efficient than postfix operations.
As for std::endl - the main thing to remember is that it sends a newline
and flushes the output buffers. This flush operation is basically negligible if you're just doing simple console output. The only time you need to worry about the performance of the flush is when you are putting out a
lot of data to a stream (this goes for both console and file streams, by the way).
The best thing to do is just use endl where you normally would, and
if it becomes a performance concern, then consider only using "\r\n" and sending a flush (or endl) less often. If it isn't causing performance problems, don't worry about it.