c++ - "Error: no operator for cin>>"我可以 't figure out what I' m 在这里做错了

标签 c++ input compiler-errors

我是一名学生,上周才开始学习 C++,所以这个问题可能水平很低,但我想不通。

我搜索了一下,但找不到任何结果,或者我正在寻找错误的东西。

有两个 cin 部分。一个在循环外接受一个 int,另一个在循环内接受一个字符串。

即使我在 5 行前才使用过它们,但我收到一个编译错误,提示“错误,没有操作符匹配这些命令”。

帮忙吗?

#include <fstream>
#include <iostream>

using namespace std;

int main()
{
    // variable declaration
    const double payIncrease = 7.6;
    string employeeName;
    double initialSalary;
    double backPay;
    double employeeAnnualSalary;
    double employeeMonthlySalary;

    int numEmployees;

    // streams of information
    ofstream outStream;
    outStream.open("employeeRecords.txt");

    // console io's
    cout<<"Enter how many employees you have:";
    cin>>numEmployees;

    for(int i = 0; i <numEmployees;i++)
    {
            cout<<"What is Employee number: "<<i<<"'s name:";
            cin>>employeeName;

            cout<<"How much does that employee earn now: ";
            cin>>initialSalary;
    }

    outStream <<"annual salary was: " << numEmployees;
    outStream.close();

    return 0;

最佳答案

这是一个实际编译的版本。你可以自己弄清楚你错过了什么 ;-)

#include <iostream>
#include <string>
using namespace std;

int main()
{
    cout << "Enter how many employees you have:";
    int numEmployees = 0;
    cin >> numEmployees;

    for(int i = 0; i < numEmployees; ++i)
    {
        cout << "What is Employee number: " << i << "'s name:";
        string employeeName;
        cin >> employeeName;
    }
}

关于c++ - "Error: no operator for cin>>"我可以 't figure out what I' m 在这里做错了,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3762371/

相关文章:

java - 如何在一行中准确输入五个字符的字符串,然后输出每个字符之间有空格的字符串? java

java - 读取文本文件中的下一行

intellij-idea - IntelliJ : “java connot find symbol class” when class is in same package

erlang - “head mismatch”编译器错误是什么意思?

c++ - 如何转储无序映射,同时添加和删除元素?

c++ - 如何更改 $Extend 目录的权限? Python? C++?

c++ - 读取由空格或换行符分隔的输入...?

C++内存扫描

c中的复数输入

Scala 类型参数不符合类型参数范围