cin.get() 导致"no instance of overloaded function"错误



我正在为一个类处理的C++项目遇到了一些问题。我不断收到一条错误消息,指出"没有重载函数的实例"。我做了一些谷歌搜索,似乎每个人都说这个错误是由将字符串传递到 cin.get(( 函数引起的,但我将这个函数与字符一起使用,而不是字符串。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; 
}

nameFull是一个char数组(更具体地说是char[30](,它衰减到指向字符(char*(的指针。没有接受单个指向字符的指针的重载std::istream::get,但有一个重载接受指针+ 要读取的缓冲区大小。

因此,您需要做的就是传递一个附加参数:

cin.get(nameFull, 30);

相关内容

最新更新