gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 15:52:34 26 4
gpt4 key购买 nike

我尝试在 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com