【发布时间】:2019-09-15 19:48:08
【问题描述】:
我正在为一个班级工作的 C++ 项目遇到一些问题。我不断收到一条错误消息,指出“没有重载函数的实例”。我做了一些谷歌搜索,似乎每个人都说这个错误是由将字符串传递给 cin.get() 函数引起的,但我将此函数与 char 一起使用,而不是字符串。 Visual Studio 说错误在:“cin.get(nameFull);”但我已将 nameFull 定义为字符,而不是字符串。任何帮助将不胜感激,感谢您的宝贵时间。
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
const int MONTHS = 12;
const int RETRO_MONTHS = 6;
char nameFull[30]; // INPUT - Employee's full name
float salaryCurrent; // INPUT - Current annual salary
float percentIncrease; // INPUT - Percent increase due
float salaryNew; // OUTPUT - New salary after increase
float salaryMonthly; // OUTPUT - New monthly salary
float retroactivePay; // OUTPUT - Retroactive pay due employee
int count; // CALC - Counter for loop
for (int count = 0; count < 3; count++) {
cout << "What is your name?" << endl;
cin.get(nameFull);
cout << "What is your current salary?" << endl;
cin >> salaryCurrent;
cout << "What is your pay increase?" << endl;
cin >> percentIncrease;
salaryNew = salaryCurrent + (salaryCurrent * percentIncrease);
salaryMonthly = salaryNew / MONTHS;
retroactivePay = (salaryNew - salaryCurrent) * RETRO_MONTHS;
cout << nameFull << "'s SALARY INFORMATION" << endl;
cout << "New Salary"
<< setw(20) << "Monthly Salary"
<< setw(20) << "Retroactive Pay" << endl;
cout << setprecision(2) << fixed << setw(10) << salaryNew
<< setw(20) << salaryMonthly
<< setw(20) << retroactivePay << endl;
cout << "<Press enter to continue>" << endl << endl;
cin.get();
}
return 0;
}
【问题讨论】:
-
您的意思是
getline (cin, nameFull);? (虽然最好让nameFull输入std::string)
标签: c++ syntax-error