呼叫错误没有匹配功能 [英] No matching function for call error

查看:90
本文介绍了呼叫错误没有匹配功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不断从我的程序中收到此错误。

I keep getting this error from my program.

22	26	C:\Users\Earl i&\Desktop\C++ Finals\C++ FINALS.cpp	[Error] no matching function for call to 'std::basic_istream<char>::getline(std::string&, int)'



我想知道造成这种情况的原因



我尝试了什么:




I want to know what's causing it

What I have tried:

#include <iostream>
#include <fstream>
#include <string>

using namespace std;

int main()
{
 const int studentCount = 2;
 ofstream outputFile;
 outputFile.open("earlfoz.txt");
 
 outputFile.clear();
 string name[studentCount];
 int grade[studentCount];
 int index[studentCount];
 int i, j;

 for(i=0;i<studentCount;i++)
 {
  cout << "Please enter of student ["<<i<<"]: ";
  cin.getline(name[i],255);
 
  cout << "Please enter grade: ";
  cin.getline(name[i],255);
  cout<<endl;
 }

 for(i=0;i<studentCount;i++)
 {
  index[i]=i;
 }

 for(i=0;i<studentCount;i++)
 {
  for(j=i+1;j<studentCount;j++)
  {
   int temp;
   
   if(name[index[i]] > name[index[j]])
   {
    temp = index[i];
    index[i] = index[j];
    index[j] = temp;
   }
  }
 }
 cout << endl;

 for(i=0;i<studentCount;i++)
 { 
  cout << name[index[i]] << "        "
   << grade[index[i]] << endl;
 }
 
for(i=0;i<studentCount;i++)
 { 
   outputFile<< name[index[i]]<<"\t";
   outputFile<< grade[index[i]];
   outputFile<<endl;
 }
outputFile.close();

cout<<"\nSorted List Successfully Printed!!!"<<endl;
 cin.ignore();
 cin.get();

 
}

推荐答案

参见 istream :: getline [ ^ ]。 getline方法不接受字符串引用。
See istream::getline[^]. the getline method does not take a string reference.


Richard 的解决方案外,请注意有一个 getline 接受字符串的全局函数作为参数,请参阅 std :: getline - cppreference.com [ ^ ]用于参考和示例代码。
In addition to Richard's solution, please note there is a getline global function accepting a string as argument, see std::getline - cppreference.com[^] for refenece and sample code.


这篇关于呼叫错误没有匹配功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆