成员引用基本类型'char'不是C ++中的结构或联合

时间:2018-08-29 14:48:49

标签: c++

有人可以帮我用C ++调试此问题吗? 如果用户要再次输入,我希望它循环播放,但是错误不断出现。

void typeA(){
    int j;
    char dec;
    do{
        cout << "Enter Month: ";
        cin >> month[j];
        cout << "Enter Date: ";
        cin >> date[j];
        cout << "Enter Time in Hour: ";
        cin >> aHours[j];
        cout << "Enter Time in Minutes: ";
        cin >> aMins[j];
        cout << "Enter Time Out Hour: ";
        cin >> aHours[j];
        cout << "Enter Time Out Minutes: ";
        cin >> aMins[j];

        cout << "Enter Again?: [y/n]";
        cin >> dec;

    }while(!dec.compare('y'));
    cout << "Exit";

}

1 个答案:

答案 0 :(得分:1)

您应该使用==运算符来检查两个fundamental types是否相等,因为C ++中的基本类型不能具有方法。

void typeA(){
    int j;
    char dec;
    do{
        cout << "Enter Month: ";
        cin >> month[j];
        cout << "Enter Date: ";
        cin >> date[j];
        cout << "Enter Time in Hour: ";
        cin >> aHours[j];
        cout << "Enter Time in Minutes: ";
        cin >> aMins[j];
        cout << "Enter Time Out Hour: ";
        cin >> aHours[j];
        cout << "Enter Time Out Minutes: ";
        cin >> aMins[j];

        cout << "Enter Again?: [y/n]";
        cin >> dec;

    }while(dec == 'y');
    cout << "Exit";

}