注册 登录
编程论坛 VC++/MFC

c++小程序问题求教?

chenbofeng20 发布于 2012-08-07 16:43, 534 次点击
#include <iostream>
#include <string>
 using namespace std;

 struct StudentInfo  //定义学生信息机构体
 {
     string strName;
     int chinese;
     int math;
     int english;
 };
 StudentInfo student[3];
void StudentInput()  //学生信息输入函数
 {
     int i = 0;
     for(i;i<3;i++)
     {
         cout<<"Enter the "<<i+1<<" student information.\n"<<endl;
         cout<<"Enter Name:"<<endl;
         cin>>student[i].strName;
         cout<<"Enter chinese"<<endl;
         cin>>student[i].chinese;
         cout<<"Enter math"<<endl;
         cin>>student[i].math;
         cout<<"Enter english"<<endl;
         cin>>student[i].english;
     }
 }
void StudentOut()//学生信息输出函数
{
    for(int i=0;i<3;i++)
    {
        cout<<"The "<<i+1<<" student information"<<endl;
        cout<<"Name : "<<student[i].strName<<"\n"<<endl;
        cout<<"Chinese : "<<student[i].chinese<<"\n"<<endl;
        cout<<"Math : "<<student[i].math<<"\n"<<endl;
        cout<<"English : "<<student[i].english<<"\n"<<endl;
    }
}
int main()
{
    StudentInput();   
    StudentOut();
    cin.get();
    return 0;
}
我在输入3个学生的信息后,敲回车程序直接退出了,未能显示出输入的学生信息。
3 回复
#2
chenbofeng202012-08-07 16:51
急!!!在线等答案
#3
修雅2012-08-08 09:49
你的程序没有错 只不过是在执行完最后一步之后 它自动退了出来 以至于你还没来的急看到结果
int main()
{
    StudentInput();
    StudentOut();
    getch();
    return 0;
}
头文件上包含conio
这样他在最后一步执行完了之后,你按下回车他才会退出来


[ 本帖最后由 修雅 于 2012-8-8 10:01 编辑 ]
#4
chenbofeng202012-08-08 15:07
问题解决,非常感谢!
1