_TCHAR
, i.e. TCHAR
is a type that depends on your project's settings. It can be either wchar_t
(when you use Unicode) or char
(when you use Multi-byte). You will find this in Project Properties - General, there's a setting Character Set.
Probably the simplest thing that you could do is just to use multi-byte option and treat _TCHAR*
type as a simple char*
and use it to construct std::string
object ASAP:
std::string filename(argv[1]);
But in case you are going to work with special characters A LOT, then I find it more reasonable to use Unicode and hold strings in form of std::wstring
objects wherever it's possible. If that's the case, then just use std::wstring
's constructor instead:
std::wstring filename(argv[1]);
And in case you'll end up working with wide strings, sometimes you'll need a conversion between wide strings and multi-byte strings and these helpers might help you:
// multi byte to wide char:
std::wstring s2ws(const std::string& str)
{
int size_needed = MultiByteToWideChar(CP_UTF8, 0, &str[0], (int)str.size(), NULL, 0);
std::wstring wstrTo(size_needed, 0);
MultiByteToWideChar(CP_UTF8, 0, &str[0], (int)str.size(), &wstrTo[0], size_needed);
return wstrTo;
}
// wide char to multi byte:
std::string ws2s(const std::wstring& wstr)
{
int size_needed = WideCharToMultiByte(CP_ACP, 0, wstr.c_str(), int(wstr.length() + 1), 0, 0, 0, 0);
std::string strTo(size_needed, 0);
WideCharToMultiByte(CP_ACP, 0, wstr.c_str(), int(wstr.length() + 1), &strTo[0], size_needed, 0, 0);
return strTo;
}