值的量我有一个结构伯爵表中的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'而不是一个数组,并且它会保持它包含的项目的数量。 –