没有从'const char *'转换为'int'

时间:2014-04-04 18:58:47

标签: char int type-conversion

有人可以帮助我解决这个问题吗?我没有得到' const char *'到' int'在我的第一个'如果'声明行。有人能告诉我我做错了吗?

char            Vtype,
            Vehicle;
int             HI,
            HO,
            MI,
            MO,
            Ctime,
            Catime,
            Btime,
            Basub,
            Ttime,
            Tasub;
double          Ctotal,
            Batot,
            Bbtot,
            Btotal,
            Tatot,
            Tbtot,
            Ttotal;
const double    C_Rate = 1.25,
            B1_Rate = 2.00,
            B2_Rate = 2.50,
            T1_Rate = 3.75,
            T2_Rate = 4.50;
cout << "TYPE OF VEHICLE: ";
cin >> Vtype;

    if (Vtype == "C" || Vtyp == "B" || Vtype == "T")
    {
        cout << "HOURS IN: ";
        cin >> HI;
        if (HI < 0 || HI > 23)
        {
            cout << "Hours cannot be less than 0 or greater than 23!\n";
            cout << "Please enter a valid hour.\n";
            cin >> HI;
        }

谢谢,

Ť

1 个答案:

答案 0 :(得分:0)

如果Vtype是char,请将其与字符进行比较:

if (Vtype == 'C' || Vtype == 'B' || Vtype == 'T') {
}

编译器指责您将const char *int进行比较,因为就C ++而言,字符整数。

或者,如果您需要将其与字符串进行比较,请将其声明为std::string