#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調用都在的第一個函數中。編譯器專門調用第三個,第五個和最後一個,但我很確定它們都有問題。收到錯誤「沒有匹配函數調用'getline(std :: ifstream&,int&,char)'」
getline(FileIn, si.sn.custID, '\n');
這是一個問題:
'geline()'只接受'串'作爲第二個參數,你需要把它放在一個字符串,然後將其轉換成'int'或其他類型。由於結構中的某些成員的類型爲'int' –
@JohnMarkCaguicla將成員更改爲字符串會更容易嗎?這可能導致什麼問題? – LCro
這取決於你將如何使用它們,如果你只是顯示它們,可以將它們改爲'string',但爲了更實際的目的,你可以使用'custID'作爲int '傳遞給一個函數。在這種情況下,只需將其作爲「字符串」進行檢索,然後將其轉換爲「int」。 –