問題是我無法輸入'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);
}
'殼體「1」: '是你最想要的東西。 –
獲取輸入函數我的班級manu – WhiteFlameBlaze