c语言文件构建步骤,C语言文件的创建与建立

本文介绍了C语言中如何创建和读取文件。通过示例代码展示了使用ofstream创建文件`clients.dat`,并从标准输入读取账户、姓名和余额数据写入文件。同时,使用ifstream读取文件内容并展示。文中还提到了输入提示符`?`的疑问,等待进一步解答。
摘要由CSDN通过智能技术生成

C语言文件的创建与建立

c语言中对于文件的创建与建立已经有相当经典且应用相当广泛的语法了。下面是小编为大家带来的C语言文件的创建与建立的知识,欢迎阅读。

首先是文件的创建:

# include

# include

# include

using namespace std;

int main() {

ofstream outclientfile("clients.dat", ios::out);

if (!outclientfile) {

cerr << "file could not be opend" << endl;

exit(1);

}

cout << "enter the account,name,and balance." << endl;

cout<< "enter end-of-file to end input.

?";

int account;

char name[30];

double balance;

while (cin >> account >> name >> balance) {

outclientfile << account << " " << name << " " << balance << endl;

cout << "?";

}

system("pause");

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值