Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/155.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ LPWSTR比较_C++_Visual Studio - Fatal编程技术网

C++ LPWSTR比较

C++ LPWSTR比较,c++,visual-studio,C++,Visual Studio,如何正确处理本例中的if语句: int n_args = 0; int i; LPWSTR *args = CommandLineToArgvW(GetCommandLineW(), &n_args); if (args) { if (n_args >= 2) { for (i = 1; i < n_args; i++) { std::cout << args[i] << "\n"

如何正确处理本例中的
if
语句:

int n_args = 0;
int i;
LPWSTR *args = CommandLineToArgvW(GetCommandLineW(), &n_args);
if (args)
{
    if (n_args >= 2)
    {
        for (i = 1; i < n_args; i++)
        {
            std::cout << args[i] << "\n";
            if (args[i] == L"/D") // <-- here
            {
                std::cout << "Condition met\n";
            }
        }
    }
}
int n_args=0;
int i;
LPWSTR*args=CommandLineToArgvW(GetCommandLineW(),&n_args);
如果(args)
{
如果(n_args>=2)
{
对于(i=1;i您正在尝试比较两个指针值。您需要使用
strcmp
或其宽字符串版本
wcscmp
。当字符串包含相同内容时,此函数返回0。

args[i]是字符串。您需要使用wcscmp或strcmp比较两个字符串。
另外,
std::cout
没有
Win32 API有自己的
lstrcmpW()
CompareStringW()
/
CompareStringEx()
函数,而
wcscmp()
来自C运行时库。只需指出,使用指针比较字符串值有多种方法。
if (wcscmp(L"/D", args[i]) == 0)
{