“错误:没有用于cin的运算符”我无法弄清楚我在做什么错 [英] "Error: no operator for cin>>" I can't figure out what I'm doing wrong here
问题描述
我是一名学生,上周才开始学习C ++,所以这个问题的水平可能很低,但我无法弄清楚。
I'm a student and just started learning C++ last week so this question is probably very low level but I can't figure it out.
我已经搜索了一下,但找不到任何结果,或者也许我在找错东西。
I've searched around a bit but can't find any results, or maybe I'm looking for the wrong thing.
有两个cin部分。一个在循环外输入一个int,另一个在循环内输入一个字符串。
There are two cin parts. One taking in an int outside the loop, the other taking in a string inside the loop.
我收到一个编译错误,上面写着错误:没有运算符匹配这些命令,即使我只是在5行之前使用过它们。
I'm getting a compile error saying ""Error no operator matches these commands" even though I just used them 5 lines ago.
帮助?
#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;
}
推荐答案
此处是实际编译的版本。您可以自己弄清楚自己错过了什么;-)
Here is a version that actually compiles. You can figure out what you missed on your own ;-)
#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;
}
}
这篇关于“错误:没有用于cin的运算符”我无法弄清楚我在做什么错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!