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

时间:2014-08-09 23:47:52

标签: c++ char int getch incompatibletypeerror

我最近尝试用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 ++,而且我仍然需要一个解决方案。 感谢

1 个答案:

答案 0 :(得分:2)

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

替换它
char First;