问题是我无法输入“c”的值,它是一个无限循环。我看不出我做错了什么。我对 C++ 很陌生。
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
class manu
{
private:
int sqdno;
string name,speciality,take;
ofstream fileip;
ifstream fileop;
public:
manu()
{
fileip.open("Manchester United.txt");
fileop.open("Manchester United.txt");
}
public:
int input()
{
while(cin>>sqdno>>name>>speciality)
{
fileip<<sqdno<<' '<<name<<' '<<speciality<<endl;
}
}
public:
int display()
{
fileop>>take;
while(fileop.good())
{
cout<<take<<endl;
fileop>>take;
}
}
};
int main()
{
int c;
manu m;
cout<<"Enter squad details(press 'Ctrl+z' to exit on input):\n";
do
{
cout<<"Select a choice:"<<endl;
cout<<"1.Input to file"<<endl;
cout<<"2.Display from file"<<endl;
cout<<"3.Exit"<<endl;
cin>>c;
switch(c)
{
case 1:
cout<<"Input squad_no,name and speciality of players:";
m.input();
break;
case 2:
m.display();
break;
default:
cout<<"enter a valid choice";
}
}while(c<3);
}