对文本文件score.txt进行输入/输出(P308)
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
	char id[11],name[21];
	int score;
	ofstream outFile;							
	outFile.open("score.txt",ios::out);				//以写方式打开文本文件
	if(!outFile)									//条件成立,则说明文件打开出错
	{
		cout<<"创建文件失败"<<endl;
		return 0;
	}
	cout<<"请输入:学号 姓名 成绩(以Ctrl+Z结束输入)\n";
	while(cin>>id>>name>>score)
		outFile<<id<<" "<<name<<" "<<score<<endl;	//向流中插入数据
	outFile.close();
	return 0;
}
 
                    
                     
                    
                 
                    
                
 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号