对文本文件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;
}

 

posted @ 2020-04-11 08:50  CollisionDimension  阅读(281)  评论(0)    收藏  举报