Printing out self path
Why does the following code print out only one character with printf and some hex code with cout when it is supposed to print out the string in s??
you're probably compiling with unicode character set enabled. try changing your compiler settings to compile using multi-byte strings instead of unicode.
Or, you know, use std::wcout. Can't guarantee it will print out anything eligible, though. The standard is broken in regards to wchar.
Oh yeah, and NULL should be nullptr.
If you're using c++11. Otherwise, old-style C++ practice is to simply use 0.
Originally Posted by Elysia
IMO, you should set your character set to "not set" and get rid of things like TCHAR and TEXT, etc. Why complicate things if you don't need to?
It is also a really bad idea to mix usage of printf() and streaming to std::cout. In general, it is a bad idea to mix C and C++ style output to the same device or stream, as the two are not required to be synchronised.
Whichever method you use, it does pay to flush the stream (or output a newline).
Given that TCHAR is not necessarily the same as char, you need to be a bit more careful in selecting printf() format strings. Or convert the TCHAR's to char before outputting.
Using nullptr is not a bad idea if your compiler supports C++-11. But that is a style thing, not a specific technical requirement (GetModuleFileName() is specifically documented as able to accept NULL, and this will work as the win32 API existed before nullptr did).
You could also try printing out argv (which is guaranteed to be a pointer to char), subject to a check that it is non-NULL. Bear in mind that argv is not guaranteed to be a completely qualified path name.