我是一名学生,上周才开始学习 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/