c++ - 接收错误 "no matching function for call to ' getline(std::istream&, int&, char )'"

标签 c++ compiler-errors getline

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

using namespace std;

struct subscriberName
{
   string first;
   string last;
   int custID;
};

struct address
{
   string address2;
   string city;
   string state;
   int zipcode;
};

struct date
{
   string month;
   int day;
   int year;
};

struct renewal_information
{
   int monthsLeft;
   date da;
};

struct subscriberInfo
{
   subscriberName si;
   address ad;
   renewal_information ri;
};


int main()
{
   void OpenFileIn(ifstream& FileIn, string& FilenameIn);
   void OpenFileOut(ofstream& FileOut, string& FilenameOut);
   bool ProcessCustInfo(bool& truth, ifstream& FileIn);
   void OutputCustInfo(ifstream& FileIn, ofstream& FileOut);

   ifstream FileIn;
   ofstream FileOut;
   string FilenameIn;
   string FilenameOut;
   bool truth;
   subscriberInfo si;


   OpenFileIn(FileIn, FilenameIn);

   OpenFileOut(FileOut, FilenameOut);

   ProcessCustInfo(truth, FileIn);

   OutputCustInfo(FileIn, FileOut);
   return 0;
}

bool ProcessCustInfo(bool& truth, ifstream& FileIn, subscriberInfo& si)
{
   getline(FileIn, si.sn.first, '\n');                   //here
   getline(FileIn, si.sn.last, '\n');
   getline(FileIn, si.sn.custID, '\n');
   getline(FileIn, si.ad.address2, '\n');
   getline(FileIn, si.ad.city, '\n');
   getline(FileIn, si.ad.state, '\n');
   getline(FileIn, si.ad.zipcode, '\n');
   getline(FileIn, si.ri.monthsLeft '\n');        //to here




}



void OutputCustInfo(ifstream& FileIn, ofstream& FileOut, subscriberInfo& si)
{
   if(si.ri.monthsLeft=0)                     //here down to
   {
      FileOut << string(55,'*') << endl;
      FileOut << si.sn.first << " " << si.sn.last << "(" << si.sn.custID << ")" << endl;
      FileOut << sn.ad.address2 << endl;
      FileOut << sn.ad.city << ", " << sn.ad.state <<sn.ad.zipcode << endl;
      FileOut << "The last renewal notice was sent on " <<sn.ri.da.month << " " << sn.ri.da.day << ", " << sn.ri.da.year << endl;          //here
      FileOut << string(55,'*') << endl;
   }
}

我不知道是什么导致了这个错误。它出现在所有 getline 调用所在的第一个函数中。编译器专门调用了第三个、第五个和最后一个,但我很确定它们都有问题。

最佳答案

您正在将 int 类型的变量传递给 getline in:

getline(FileIn, si.sn.custID, '\n');

这是个问题。

使用:

std::string custID;
getline(FileIn, custID, '\n');
si.sn.custID = std::stoi(custID);

你有同样的问题:

getline(FileIn, si.ad.zipcode, '\n');

getline(FileIn, si.ri.monthsLeft '\n');

也行

if(si.ri.monthsLeft=0)

错了。我怀疑这是一个错字。您需要使用 == 而不是 =

if(si.ri.monthsLeft == 0)

关于c++ - 接收错误 "no matching function for call to ' getline(std::istream&, int&, char )'",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33728025/

相关文章:

c++ - 为什么在使用组合而不是继承时出现 C4624(基类析构函数不可访问)?

c# - 如何检测接口(interface)和实现类之间的默认参数值不匹配?

visual-c++ - vc++ 6.0 中的 long long int 编译错误

ubuntu - 当我尝试在 MonoDevelop 上编译时,有谁知道这个错误是什么?

c++ - 获取线路如何工作?

c++ - 如何对未知数据量使用 getline()?

c++ - 何时以及为什么需要在 C++ 中使用 cin.ignore()?

c++ - 是否可以显式特化模板以匹配 lambda?

c++ - 使用 foo::bar 不会屏蔽 typedef-name::bar?

c++ - 链接到内核