Is it wrong to use the main function in C++ Visual Studio 2017 as following:
int main(int argc, wchar_t* argv[])
as my program can receive special characters.
Is it wrong to use the main function in C++ Visual Studio 2017 as following:
int main(int argc, wchar_t* argv[])
as my program can receive special characters.
Please go and read the remarks section on GetCommandLine
:
ANSI console processes written in C can use the argc and argv arguments of the main function to access the command-line arguments. ANSI GUI applications can use the lpCmdLine parameter of the WinMain function to access the command-line string, excluding the program name. The main and WinMain functions cannot return Unicode strings.
Unicode console process written in C can use the
wmain()
or_tmain()
function to access the command-line arguments. Unicode GUI applications must use the GetCommandLineW function to access Unicode strings.To convert the command line to an argv style array of strings, call the CommandLineToArgvW function.
Yes, but if you need to perform input and output operations, perhaps you need to add std::setlocale(LC_ALL, "");
, because by default it only supports the most basic English character output.
example:
int wmain(int argc, wchar_t* argv[])
{
std::setlocale(LC_ALL, "");
wstring str = argv[1]; //if argv[1] contains unicode characters, such as"你好"
wcout << str << endl;
return 0;
}