我在编译器中收到以下错误:
AccountDB.cpp:在成员函数'void AccountDB :: processTransactions(const char *)'中: AccountDB.cpp:89:9:错误:在'。'标记之前的预期初始化程序 inFile2.open(transactFile); ^(胡萝卜超过期限)
这是相关功能。从这里的类似错误,我怀疑它与命名空间有关,但我不确定是哪一个。该函数应该读取事务的日期,帐号和金额,然后使用其他嵌套函数处理它。
void AccountDB::processTransactions(const char* transactFile)
{
//set up the input stream from the text file
ifstream inFile2;
//set up the variables to be read from text file
char date[6];
char type;
char accountnumber[20];
double amount,
//open the file
inFile2.open(transactFile);
//standard check for file and exit if it doesn't exist
if(!inFile2)
{
cout << "Error, input file could not be opened.\n";
exit(1);
}
//Creates a header for listing transactions
cout << setw(5) << "Date"
<< setw(25) << "Account Number"
<< setw(5) << "Type"
<< setw(8) << "Amount"
<< setw(30) << "New Balance"
<< endl;
inFile2 >> date;
while (inFile2)
{
inFile2 >> accountnumber >> type >> amount;
cout << setw(5) << date
<< setw(25) << accountnumber[20]
<< setw(5) << type
<< setw(8) << amount;
int relevantAccount = searchForAccount(accountnumber);
if (relevantAccount != -1)
{
if (type == 'P')
{
credArray[relevantAccount].processPayment(amount);
cout << setw(30) << credArray[relevantAccount].getBalance() << endl;
}
else
{
bool chargestatus = credArray[relevantAccount].processCharge(amount);
if (chargestatus = 1)
cout << setw(30) << credArray[relevantAccount].getBalance() << endl;
else
cout << "Credit limit exceeded" << endl;
}
}
else
cout << "Invalid account number" << endl;
inFile2 >> date;
}
cout << "End of transaction list." << endl;
}
答案 0 :(得分:1)
变量声明后有逗号:
double amount, // ^
将其更改为分号;
。