c++ - "error: conversion from ' 整数 ' to non-scalar type ' 坐标 ' requested"

标签 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;
}

最佳答案

COORD pos = (40, 3);

这应该是:

COORD pos = {40, 3};

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

关于c++ - "error: conversion from ' 整数 ' to non-scalar type ' 坐标 ' requested",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5575538/

相关文章:

c++ - 使指向特定托管对象的所有共享指针无效

c++ - 带数字的优化算法

c++ - Eclipse CDT : no rule to make target all

c++ - 带有字符的奇怪指针行为

c++ - 当 TFramedTransport 打开时,thrift 中的 TNonblockingServer 崩溃

c++ - 如何获取工作站所属的 Active Directory 域的全名

c++ - 为什么 GCC 的 std::function 不使用对按值传递的参数的右值引用在其内部委托(delegate)之间传递它们?

c++ - Python-C++ 接口(interface)中的内存泄漏?

c++ - 将 initialOwner 设置为 TRUE 的 CreateMutex 使创建者进程保持互斥直到完成

C++ 代码神奇地将 1 添加到输出