二进制表达式的操作数无效错误消息

Invalid operands to binary expression error message

本文关键字:错误 消息 无效 操作数 表达式 二进制      更新时间:2023-10-16

我在编程方面真的很新(我正在学习C++)。有人可以告诉我为什么我在尝试运行这段代码时收到此错误消息。

int main()
{
    auto days=0, hours_worked=0;
    cin  >> "days"; // This is where I get the error message.
    cout << "Days worked per week";
    cin  >> "hours_worked"; // This is where I get the error message.
    cout << "Hours worked per day";
    cout << "This week Paul worked: "
         <<"6*9"<< endl;
    return 0;
}
#include <iostream>
using namespace std; //we are going to use std::cin, std::cout, std::endl from the header file <iostream>
int main()
{
    int days=0, hours_worked=0; //why not just declare it as integer?
    cin  >> days; //you need to write it without "" otherwise its treated as a string and not a variable
    cout << "Days worked per week" << days; //no. of days the person worked
    cin  >> hours_worked; // same here
    cout << "Hours worked per day" << hours_worked;
    cout << "This week Paul worked: "
         << (days*hours_worked) << " hours" << endl; //paul worked (days*hours_worked) hours
    return 0;
}

是更正后的代码。 希望您理解更正。