2011-04-07 114 views
0

我在尝试编译code :: blocks中的以下代码时出现此单列错误。
错误发生了8行。“错误:从'int'转换为非标量类型'COORD'请求”

#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; 
} 

回答

5
COORD pos = (40, 3); 

这应该是:

COORD pos = {40, 3}; 

注意,而不是使用{}()。

+0

非常感谢。 – 2011-04-07 03:20:52

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

感谢您的快速回答,但我需要更改(到{。 – 2011-04-07 03:43:47

相关问题