gpt4 book ai didi

c++ - 设置 ifstream,获取 'error: expected initializer before ‘.’ token '

转载 作者:行者123 更新时间:2023-11-28 07:05:23 24 4
gpt4 key购买 nike

我在编译器中收到以下错误:

AccountDB.cpp:在成员函数‘void AccountDB::processTransactions(const char*)’中:AccountDB.cpp:89:9: 错误:'.' 标记之前的预期初始值设定项inFile2.open(交易文件); ^(胡萝卜过期了)

这是相关的功能。从这里的类似错误来看,我怀疑它与命名空间有关,但我不确定是哪个。该函数应该读取交易的日期、帐号和金额,然后使用其他嵌套函数对其进行处理。

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;

最佳答案

变量声明后有一个逗号:

double amount,
// ^

将其更改为分号 ;

关于c++ - 设置 ifstream,获取 'error: expected initializer before ‘.’ token ',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21841488/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com