2016-04-04 5 views
-2

[OK]をので、私は私の問題は、プログラムは、私が口座からmain.cppになぜ以前のエントリを読み取れないのですか?

void new_account() 
{ 
    class account arcade; 
    ofstream outfile; 
    outfile.open("account.txt",ios::app|ios::binary); 
    arcade.create_account(); 
    outfile.write((char *)(&arcade), sizeof(account)); 
    outfile.close(); 

} 

void display_account(int acc_no) 
{ 

    account arcade; 
    ifstream infile; 
    infile.open("account.txt",ios::binary); 
    while(infile.read((char *)(&arcade), sizeof(account))); 
    { 
     if(arcade.getaccount_no() == acc_no) 
     { 
      arcade.show_account(); 
     } 
    } 
    infile.close(); 
} 

から

を入力した以前のエントリを読むようには見えないということです バンク管理システムを作成しています。 cppファイル

void account::create_account() 
{ 

    cout << "1.Enter account no" << endl; 
    cin >> account_no; 
    cout << "2.Enter username" << endl; 
    cin.ignore(); 
    cin.getline(name,50,'\n'); 
    cout << "Enter initial deposit" << endl; 
    cin >> deposit; 
    cout << "Your account has been created" << endl; 
    getch(); 
} 

void account::show_account() 
{ 
    cout <<"Account No. :"<<account_no <<endl; 
    cout <<"Account User Name: " << name << endl; 
    cout <<"Balance Amount" <<deposit << endl; 


} 

新しいエントリを追加する場合は、その後、新しいエントリを表示しようとすると、そのエントリが表示されます。しかし、私が以前に記憶したエントリーはアクセスできません。

+0

あなたが表示したコードが[mcve]の要件を満たしていません。ヘルプセンターでこの記事を確認し、コードが[mcve]の要件を満たすように質問を編集してください。 –

+0

これは実際の銀行ではありませんか? –

+0

@NicolasHolthaus nope。そのちょうどC++プロジェクト –

答えて

0

私があなたが共有していることから分かることは、複数の人/番号/情報を処理するためのアレイ設定がないことです。

gin.getline(name[I],50,'\n'); 

これは、毎回別々の変数を別々に作る必要なく、メモリ内の別の場所に各エントリを格納します。

関連する問題