Search code examples
c++charintgetchincompatibletypeerror

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


I'm recently trying to make a game in c++ and this is the code.

    #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;}
    }

My Dev-c++ compiler says [Error] imconpatible types in assignment of 'int' to 'char[1]'

I'm not really good at c++ right now and i'm stil lerning and i need a solution. thanks


Solution

  • Why do you use char First[1]? It is one-element array of elements of type char. Replace it with just

    char First;