首页 > 解决方案 > 简单的 C++ 代码在 Visual Studio 中不起作用

问题描述

#include<iostream>
#include<windows.h>

using namespace std;

int main()
{

    HWND hwnd = FindWindowA(NULL, "Terraria Part 3: The Return of the Guide");
    if (hwnd == NULL)
    (
        cout << "cannot find window." << endl;
        Sleep(3000);
        exit(-1);
    )

        return 0;
}

我写的这个和我正在看的视频告诉我的完全一样,它给了我一个 Microsoft Visual Studio 错误代码,但如果我取出它就可以工作 ( cout << "cannot find window." << endl; Sleep(3000); exit (-1);)

标签: c++windowsvisual-studio

解决方案


您的if 语句语法错误。将 if 语句从..

if (hwnd == NULL)
    (
        cout << "cannot find window." << endl;
        Sleep(3000);
        exit(-1);
    )

至...

if (hwnd == NULL)
    {
        cout << "cannot find window." << endl;
        Sleep(3000);
        exit(-1);
    }

推荐阅读