“错误:从'int'转换为非标量类型'COORD'请求”

时间:2011-04-07 03:17:36

标签: c++

在尝试编译code :: blocks中的以下代码时,我遇到了这个单独的错误 错误发生了8行。

#include <iostream>
#include <windows.h>
using namespace std;

int main()
{
HANDLE screen = GetStdHandle(STD_OUTPUT_HANDLE);
COORD pos = (40, 3);
SetConsoleCursorPosition(screen, pos);
cout << "O" << endl;
Sleep(500);

for (int tossIt = 1; tossIt <= 3; tossIt++)
{
    while (pos.Y <= 20)
    {
        SetConsoleCursorPosition(screen, pos);
        cout << "|" << endl;
        pos.Y++;
        SetConsoleCursorPosition(screen, pos);
        cout << "O" << endl;
        Sleep(100);
    }
    while (pos.Y > 3)
    {
        SetConsoleCursorPosition(screen, pos);
        cout << " " << endl;
        pos.Y--;
        SetConsoleCursorPosition(screen, pos);
        cout << "O" << endl;
        Sleep(100);
    }
}
return 0;
}

2 个答案:

答案 0 :(得分:5)

COORD pos = (40, 3);

这应该是:

COORD pos = {40, 3};

请注意使用{}代替()。

答案 1 :(得分:1)

COORD pos = (40, 3); // (40,3) is comma expression, 3 is "retrurned"
COORD pos(40, 3); // you intent?