我不知道为什么这不起作用,这是我第一次使用该switch
声明。
int main() {
string typed;
ofstream theFile("players.txt");
ifstream theFile2("players.txt");
cout << "Do you want to read or write" << endl;
cin >>typed;
switch(typed){
case "write":
cout << "Enter players Id, Name and Money" << endl;
cout << "Press Ctrl+Z to exit\n" << endl;
while(cin >> idNumber >> name >> money){
theFile << idNumber << ' ' << name << ' ' << money << endl;
}break;
case "read":
while (theFile2 >> id >> nametwo >> moneytwo){
cout << id << ", " << nametwo << ", " << moneytwo << endl;
}break;
}
}