Lionel said:
Right! Of course I'd much rather use printf instead of std::cout <<, char*
instead of std::string, double* instead of std::vector<double>, ... but
hey, they're part of the C++ standard, so I'd better use them.
What you would prefer to use is very subjective of course but in the listed
cases there are clear technical advantages of using:
1. std::cout << instead of printf: mainly type safety and optimization
(better runtime speed), ie why not use the compile time lookup matching
types and argumets when looking for overloaded functions than telling
printf what types you will list (where you may get it wrong while the
compiler won't) also the same compiled code made to deal with various
things is generally worse optimizable than specific code ment to work with
specific types (ie an overloaded version of << than a general printf())
2. std::string instead of char*: providing safer method for string
manipulation (when not explicitely providing lengths for example) plus
simple things like always knowing the size of the string (and not having to
repeatedly call strlen() which is a O(n) operation)
3. std::vector<double> instead of double* (I supose you actually mean
instead of a C array of double because it's not the same thing with a
pointer in general thus no comparation is possible in general): not many
people know that the standard mandates that &v[0] is a contigous array that
can be manipulated externally (thus most people that wanted a C array
because they needed to work with legacy APIs can do it with std::vector
just fine) or that (most) implementations have specializations for using
std::copy() on std::vector::iterator and that in fact they actually call
memcpy and such in the cases where that is possible, etc