(Dev-c++) 将'int'分配给'char[1]'的不兼容类型

(Dev-c++) incompatible types in assignment of 'int' to 'char[1]'

本文关键字:类型 char 不兼容 分配 Dev-c++ int      更新时间:2023-10-16

我最近在尝试用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++,我还在学习,我需要一个解决方案。由于

为什么使用char First[1] ?它是包含char类型元素的单元素数组。用

代替
char First;