8i.cpp

来自「C/C++程序设计导论(第二版)》程序源文件」· C++ 代码 · 共 23 行

CPP
23
字号
// accounts.cpp  Create disk file B:ACCNTS.DAT for
//  accounts and balances
#include <iostream.h>
#include <fstream.h>
void main ()
{	char done = 'y';
	int acntnum;					// an account num.
	float balance;					// an account balance
	ofstream outfile;					// a file var.

	outfile.open ("accnts.dat");					// prepare file for writing

// Now input values from keyboard				 and write to the disk file...

	while (done != 'n')
	{	cout << "enter an account number and balance: ";
		cin >> acntnum >> balance;				 
		outfile << acntnum << " " << balance << endl;
		cout << "another account? enter `y' or `n':";
		cin >> done;
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?