void main()
is not a valid signature for your main
function (though, VS will recognize it, it is not standard-compliant). It should be int main()
.
You cannot insert an integer into to a string using +
. You need to use the extraction operator of std::ostream
: operator<<
. What you have will result in pointer arithmetic (adding the result from doIt
to the address of your const char*
, which is undefined behavior).
std::cout
is a buffered output stream. Since you do not flush your buffer, there is a chance that the program ends before you are able to see the output (prior to the console closing). Change your output line to one of the following:
std::cout << "test: " << doIt(myFav) << std::endl; // flush the buffer with a newline
or
std::cout << "test: " << doIt(myFav) << std::flush; // flush the buffer
All in all, what you have will compile, but will not do what you want it to, at all.