LCro
LCro

Reputation: 21

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;
   }
}

I can't figure out what is causing this error. It occurs in the first function where all the getline calls are. The compiler is specifically calling out the third, fifth, and last one, but I'm pretty sure there is something wrong with all of them.

Upvotes: 0

Views: 1555

Answers (1)

R Sahu
R Sahu

Reputation: 206567

You are passing a variable of type int to getline in:

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

That's a problem.

Use:

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

You have same problem with:

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

and

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

Also, the line

if(si.ri.monthsLeft=0)

is wrong. I suspect it is a typo. You need to use == instead of =

if(si.ri.monthsLeft == 0)

Upvotes: 1

Related Questions