我不知道,如果在Linux是使任何不同,但我已經在網上發現這一點:按任意鍵繼續在Linux下C++
cout << "Press Enter to Continue...";
cin.ignore(numeric_limits<streamsize>::max(),'\n');
應該是足夠的,與#include<limits>
當然在頭部。
但是,它似乎並沒有在我的程序中工作。
它編譯,它運行,但它不會等待。
基本上,我有一個菜單,這導致了一個方法調用來顯示屏幕上的人列表。我希望在系統返回到菜單之前暫停該列表。
這是從菜單中選擇我的代碼:
//Manager's Menu
void SelectionPage::showManagerMenu(){
char option;
while(true)
{
system("clear"); //Clears the terminal
cout<<" Flat Manager's Menu"<<endl<<endl; //Display manager's menu
cout << "Select Manager option" << endl;
cout << "a) Add a new Flat Member" << endl;
cout << "b) Delete an existing Flat Member" << endl;
cout << "c) List Flat Members" << endl;
cout << "d) Duties" <<endl;
cout << "e) Resources" <<endl;
cout << "f) Reset System" <<endl;
cout << "q) Exit" << endl;
cout << "make selection: ";
cin >> option;
switch(option) { //Takes the user to the corresponding menu or method
case 'a': system("clear");
memberList.addNewFlatMember(points);
break;
case 'b': system("clear");
memberList.deleteFlatMember();
break;
case 'c': system("clear");
memberList.listFlatMembers();
break;
case 'd': system("clear");
showDutiesMenu();
break;
case 'e': system("clear");
showResourcesMenu();
break;
case 'f': //reset();
break;
case 'q': exit(0);
default: cout << "Option not recognised: " << option << endl;
showManagerMenu();
}
}
}
我要選擇的選項爲C),這導致:
//Show the current flat population
void MemberManagement::listFlatMembers(){
cout<<" Member List"<<endl<<endl;
importFlatMembers(); //get flat member info from file
for(int count = 0; count<flatMemberList.size(); count++){
cout << count+1<<". "<<flatMemberList[count].getName() << endl;
}
cout << "Press any key to Continue...";
cin.ignore(numeric_limits<streamsize>::max(),'\n');
return;
}
如果你想看到我的代碼的任何其他位
,隨時讓我知道。
在此先感謝。
Rob's Rule#47:當你的意思是''\ n''時,千萬不要說'endl'。請參閱http://stackoverflow.com/questions/5492380/what-is-the-c-iostream-endl-fiasco –