繁体   English   中英

收到错误“没有匹配的函数调用'getline(std :: ifstream&,int&,char)'””

[英]receiving error “no matching function for call to 'getline(std::ifstream&, int&, char)'”

#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

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)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM