0
void readAccountInfo()
{
ifstream fin;
fin.open("Accounts.dat");
string tempID;
string tempFirst;
string tempLast;
string tempDeposit;
string tempRate;
string tempYear;
int i = 0;
while (fin >> tempID >> tempFirst >> tempLast >> tempDeposit >> tempRate
>> tempYear)
{
accounts[i] =
{ tempID, tempFirst, tempLast, stof(tempDeposit), stof(tempRate), stoi(tempYear)};
i++;
}
}
void writeAccountInfo()
{
ofstream fout;
fout.open("test.dat");
int i = 0;
while (i < 30 && accounts[i].yearTerm != 0)
{
fout << accounts[i].ID << " " << accounts[i].firstName << " "
<< accounts[i].lastName << " ";
fout.precision(2);
fout << accounts[i].deposit << fixed;
fout.precision(1);
fout << " " << accounts[i].rate << fixed;
fout.precision(0);
fout << " " << accounts[i].yearTerm << endl << fixed;
i++;
}
}
輸出dat文件應該有存款有兩位小數,但第一行總是以科學記數法結束。例如1000.00應該是這樣出來的,但是以1e + 3出現。爲什麼用科學記數法顯示的礦牀的第一個輸出?