fileout1.cpp

来自「高永强 全C编程源码 清华大学出版社 2002年六月第一版」· C++ 代码 · 共 23 行

CPP
23
字号
//这个程序在本书所带软盘中,文件名为FILEOUT1.CPP
//这个程序演示文件的输出。

#include <fstream.h>
#include <stdlib.h>

void main(void)
{
	ofstream out_file;						//定义一个输出文件

	out_file.open("scores.dat", ios::out);	//打开这个文件

	if(!out_file)							//检查文件建立是否成功
	{
		cout << "The file open is fail. Check the disk and try again.." << endl;
		exit(1);
	}
	out_file << 89 << "   " << 100 << "    " << 93 << endl;		//数据输出
	out_file << 78 << "   " << 79  << "    " << 82 << endl;
	out_file << "The end of the file." << endl;

	out_file.close();
}

⌨️ 快捷键说明

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