You'll see the -W error many, many times over many, many forums and tutorials because it happened to work when they were written and tested. But nobody cared to understand why. This same lack of care was exercised over a decade ago when, for instance, winprog.org wrote their tutorial. And what was the end result of that lack of care? That code samples, as they appear in the tutorial now DON'T WORK under new Visual Studio versions.
So long story short: Your code happens to work by mere luck, or coincidence. Your Visual Studio happens to be configured to #define UNICODE by default. But none of use should ever rely on chance when writing good and durable code.
Read my answer here:
http://www.cplusplus.com/forum/general/56526/
In your case, you use cout when you should have used wcout. You can make this char-agnostic like this:
1 2 3 4 5 6 7 8
|
#ifdef UNICODE
#define tcout std::wcout
#else
#define tcout std::cout
#endif
//and then use it like this:
tcout << myTCHARvariable << std::endl;
|
If you read my reply in that other thread, you should know now that you must NEVER mix data types. In your code sample, you mix a char-agnostic function name (ExpandEnvironmentStrings) with a wide char variable. This worked by good chance, but is an invalid mixture. You either use ExpandEnvironmentStringsW() or you change path's data type to TCHAR.
If you stick to TCHAR and function names without A or W, then you probably need some data types and definitions for the STL. They are very simple and you probably can declare them yourself, but just in case here are a couple of samples (besides the tcout above):
1 2 3 4 5 6 7 8 9 10 11 12 13
|
#ifdef UNICODE
typedef std::wstring tstring;
typedef std::wostringstream tostringstream;
typedef std::wistringstream tistringstream;
typedef std::wstringstream tstringstream;
//etc...
#else
typedef std::string tstring;
typedef std::ostringstream tostringstream;
typedef std::istringstream tistringstream;
typedef std::stringstream tstringstream;
//etc...
#endif
|