值的量我有一個結構伯爵表中的C++
struct number{
int value;
};
number numbers[1000];
我有一個for循環輸入值,當用戶決定離開添加面板斷離,該功能工作正常。我得到另一個for循環顯示輸入的數據,做這項工作(種),因爲它需要我使用系統(「暫停」);否則循環會不斷地輸入包含循環外部cout的函數中的所有內容。
void ListNumbers(){
system("cls");
cout << "\t\t\tArray: Numbers" << endl;;
cout << "Value" << endl;
for (int i = 0; i < 1000; i++){
if (NULL == numbers[i].value)
break;
cout << numbers[i].value << endl;
}
cout << "\n\nAmount of records: " << sizeof(numbers)/sizeof(numbers[0]) << endl;
system("pause");
我想讓程序列出表中當前充滿數據的記錄/索引的數量。目前它顯示數據庫中的記錄總量(是1000)。此外如果可能的話,固定顯示循環的方法,所以我不需要使用系統暫停將非常讚賞。
在用戶輸入記錄時保留記錄數,當您打印出來時,只打印與輸入一樣多的記錄。更好的是,使用'std :: vector'而不是一個數組,並且它會保持它包含的項目的數量。 –