Improvements suggested by CppCheck.

First set of improvements suggested by CppCheck:
* Pre-increment iterators instead of post-increment.
* Change C-style pointer cast from void* to static_cast.
* Changed pass-by-const-value to pass-by-const-referenced (I don't know which commit changed that; it seems that it appeared from nowhere).
* Removed a c_str that converted a std::string to const char* to be immediately converted back to std::string.

There are more interesting suggested improvements, by I will need some guidance because they might also have downsides.