C++文件指针的有关问题

C++文件指针的问题
 
  下面的程序,选择 2 查看的时候,第一次查看可以正常显示信息。第二次就不行了。。。
  
  文件中的内容,大家可以选1 自己输入一些。
#include<fstream>
#include<iostream>
#include<string>
using namespace std;

void main()
{
  fstream file;
  string name,sex,stuno; 
  int ctrl;
  file.open ("sturegin.txt",ios::app|ios::out|ios::in); 
  if(file.fail ())
{
cout<<"文件打开错误!"<<endl;
exit(1);
}
  while(1)
  { 
  cout<<" 1:添加资料 2:查看信息 0:保存退出";
cin>>ctrl;

switch(ctrl)
{
case 1:
while(ctrl==1)

cout<<"请输入姓名: "; cin>>name;
file<<" 姓名:"<<name<<'\n';
cout<<"请输入性别: "; cin>>sex; 
file<<" 性别:"<<sex<<'\n';
cout<<"请输入学号: "; cin>>stuno;
file<<" 学号:"<<stuno<<'\n';
cout<<"1:继续信息录入 0:退出信息录入\n";
cin>>ctrl;
} break;
case 2:
file.seekg(0,ios::beg); // !!!!!!!!
while(!file.eof())
{
getline(file,name,'\n');
getline(file,sex,'\n');
getline(file,stuno,'\n');
cout<<name<<endl;
cout<<sex<<endl;
cout<<stuno<<endl;
}
break;
case 0:
file.close();
return ;
break;

 
}
  
}
}

------解决方案--------------------
file.clear(); //添加,清楚所有状态(good state)
file.seekg(0,ios::beg); // !!!!!!!!
while(!file.eof()) //退出出时状态为eof
{