接收错误"没有匹配函数来调用' getline(std :: ifstream&,int&,char)'"

时间:2015-11-16 03:20:57

标签: 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调用的第一个函数中。编译器专门调用第三个,第五个和最后一个,但我很确定所有这些都有问题。

1 个答案:

答案 0 :(得分:1)

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

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)