0
我想清除選擇後的屏幕,但我不知道它不工作。它將顯示Display()函數和Create New Purchase等內容。這是因爲在while循環中?爲什麼系統(「CLS」)在不工作?
while (selection != -1) // While for create new purchase
{
cout << "Create New Purhcase" << endl << endl;
cout << "1. Display Item" << endl;
cout << "2. Create a New Purchase" << endl << endl <<endl;
cout << "0. Back to Main Menu" << endl;
cout << "Enter Option:";
cin >> selection;
//Back to main menu
if (selection == 0)
{
system("CLS");
break;
}
if (selection == 1)
{
system("CLS");
cout << "Display Menu" << endl;
Display();
}
void Display()
{
system("CLS");
temp = itemHead; //start at the first node
cout << "Dispaly Menu" << endl << endl;
while (temp != NULL)
{
cout << "ID:" << temp->itemid << endl;
cout << "Item Name:" << temp->name << endl;
cout << "Item Type:" << temp->type << endl;
cout << "Item Price" << temp->cost << endl;
cout << endl << endl;
temp = temp->next; //forward to the next node
}
}
http://stackoverflow.com/questions/19913446/why-should-the-system-function-be-avoided-in-c-and-c –
@Pepper:把你的問題減少到一個具體的,最小的例子,這裏的讀者可以嘗試,並完整地發佈該代碼。現在我投票結束這個問題,因爲缺乏這樣一個可重複的例子。 –
@NeilButterworth:你引用了一個關於爲什麼應該避免使用'system'的問題的鏈接,對於初學者試圖在Windows程序中清除屏幕的問題。上下文很重要。在這種情況下,該鏈接是不真實的。 –