信息录入.cpp

来自「学生通讯录系统」· C++ 代码 · 共 71 行

CPP
71
字号
#include<iostream>
#include<fstream>
#include"学生信息定义.h"
using namespace std;
void student::luru()
{
	
//	int stu_num;
//	cout<<"请输入要录入的学生个数:"<<endl;
//	cin>>stu_num;


	ofstream outfile("student.txt",ios::app);
	if(!outfile)
	{
		cerr<<"open error:"<<endl;
		exit(1);
	}
	
	cout<<"请输入下列学生信息:"<<endl;
	cout<<"姓名   学号   年龄   性别   家庭住址   电话   寝室号"<<endl;
	cout<<"姓名"<<endl;
	cin>>name;
	cout<<"学号"<<endl;
	cin>>number;
	cout<<"年龄"<<endl;
	cin>>age;
	cout<<"性别"<<endl;
	cin>>sex;
	cout<<"家庭住址"<<endl;
	cin>>addr;
	cout<<"电话"<<endl;
	cin>>phone;
	cout<<"寝室号"<<endl;
	cin>>room_num;
	outfile<<name
		<<" "<<number
		<<" "<<age
		<<" "<<sex
		<<" "<<addr
		<<" "<<phone
		<<" "<<room_num;
	outfile.close();
	cout<<"信息已成功输入!"<<endl;
		ifstream infile("studentnum.txt",ios::out);
	if(!infile)
	{
		cerr<<"open error1:"<<endl;
		exit(1);  
	}
	infile>>stu_num;
    infile.close();
	stu_num++;
	ofstream outfile1("studentnum.txt",ios::out);
	if(!outfile1)
	{
		cerr<<"open error2:"<<endl;
	    exit(1);
	}
	outfile1<<stu_num;
	outfile1.close();
	cout<<""<<endl;
	cout<<""<<endl;
	cout<<""<<endl;
	
	
}



⌨️ 快捷键说明

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