我想不通,爲什麼這不會從我的文件中讀取...從文件(C++)閱讀
#include <iostream>
#include <iomanip>
#include <string>
#include <fstream>
using namespace std;
int main()
{
int acctNum;
int checks;
double interest;
double acctBal;
double monthlyFee;
const int COL_SZ = 3;
ifstream fileIn;
fileIn.open("BankAccounts.txt");
if(fileIn.fail())
{
cout << "File couldn't open." << endl;
}
else
{
cout << left;
cout << "Bank Account records:" << endl;
cout << setw(COL_SZ) << "Account#" << setw(COL_SZ) <<
"Balance" << setw(COL_SZ) << "Interest" << setw(COL_SZ) << "Monthly Fee" << setw(COL_SZ) <<
"Allowed Checks" << setw(COL_SZ) << endl;
while(fileIn >> acctNum >> acctBal >> interest >> monthlyFee >> checks)
{
cout << setw(COL_SZ) << acctNum << setw(COL_SZ) << acctBal << setw(COL_SZ) << interest << setw(COL_SZ) <<
monthlyFee << setw(COL_SZ) << checks << endl;
}
}
fileIn.close();
system("pause");
return 0;
}
我拿出的ios ::出來,放在IOS ::在同樣的事情發生沒有數據和同樣的事情與ios在一起。我確實從以前的程序中創建文件...我必須將文件代碼讀入該程序嗎?
不應該用ifstream :: in標誌打開輸入文件而不是out? – Juancho 2011-05-03 02:13:58
+1對於酷炫的瀏覽器。 (Joking。:)) – 2011-05-03 02:45:50
對於至少有一個很酷的瀏覽器得到一個點很高興T_T – Alex 2011-05-03 04:07:51