【问题标题】:(Dev-c++) incompatible types in assignment of 'int' to 'char[1]'(Dev-c++) 将“int”分配给“char[1]”时的类型不兼容
【发布时间】:2014-08-09 23:47:51
【问题描述】:

我最近尝试用 C++ 制作游戏,代码如下。

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

    //cut

    void WritePlayerUsername(int PlayerNumber)
    {
    //clear();  this is same as system("cls");
    char First[1], Second[1], Third[1], Fourth[1], Fifth[1];
    char Sixth[1], Seventh[1], Eighth[1], Nineth[1], Tenth[1];
    cout<<"Username";
    for(int a=0; a<2; a++) cout<<endl<<endl<<endl<<endl<<endl<<endl<<endl;
    cout<<"                                                                                            [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ]"<<endl;
    gotoxy(14, 93);
    First=getch(); //Here
    cout<<First;
    gotoxy(14, 97);
    Second=getch(); //here
    cout<<Second;
    gotoxy(14, 101);
    Third=getch(); //here
    cout<<Third;
    gotoxy(14, 105);
    Fourth=getch(); //here
    cout<<Fourth;
    gotoxy(14, 109);
    Fifth=getch(); //here and something like these
    cout<<Fifth;
    gotoxy(14, 113);
    Sixth=getch();
    cout<<Sixth;
    gotoxy(14, 117);
    Seventh=getch();
    cout<<Seventh;
    gotoxy(14, 121);
    Eighth=getch();
    cout<<Eighth;
    gotoxy(14, 125);
    Nineth=getch();
    cout<<Nineth;
    gotoxy(14, 129);
    Tenth=getch();
    cout<<Tenth;
    fstream file;
    if(PlayerNumber==1){ file.open("C:\\Game\\Users\\1\\username.txt", ios::in | ios::out | ios::binary);
    file<<First<<Second<<Third<<Fourth<<Fifth<<Sixth<<Seventh<<Eighth<<Nineth<<Tenth;}
    }

我的 Dev-c++ 编译器说 [错误] 将 'int' 分配给 'char[1]' 时类型不兼容

我现在不太擅长 c++,我还在学习,我需要一个解决方案。 谢谢

【问题讨论】:

  • 您将变量定义为数组。从First[1]Second[1]等中去掉[1]

标签: c++ char int getch incompatibletypeerror


【解决方案1】:

你为什么使用char First[1]?它是char 类型元素的单元素数组。只替换它

char First;

【讨论】:

    猜你喜欢
    • 2016-03-22
    • 2013-01-21
    • 2023-03-26
    • 2013-04-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多