c++建立一个文件录入并读出学生成绩

 

简单的文件录入与读出

 

录入:
#include 
#include
#include
using namespace std;
void main()
{
	ofstream outfile("D:\\student.dat");//建立输出数据文件
	string name,id;
	int math, eng, computer;
	for (int i = 0; i < 3; i++) {
		cout << "输入姓名"; cin >> name;
		cout << "输入学号"; cin >> id;
		cout << "输入数学成绩"; cin >> math;
		cout << "输入英语成绩"; cin >> eng;
		cout << "输入计算机成绩"; cin >> computer;
		outfile << name << "" << id << "" << math << "" << eng << ""<
#include
#include
using namespace std;
void main()
{
	ifstream infile("D:\\student.dat");//找到文件
	string name,id;
	int math, eng, computer;
	for (int i = 0; i < 3; i++) {
		cout << "姓名\t" << "学号\t" << "数学成绩\t" << "英语成绩\t" << "输入计算机成绩\t" << "总分" << endl;
		infile >> name;
		while (!infile.eof()) {
			infile >> id >> math >> eng >> computer;
			cout<< name << "" << id << "" << math << "" << eng << "" << computer
				<<""<> name;

		}
	}
	infile.close();//关闭文件
}

 

你可能感兴趣的:(c++)