在我开始使用 Java 编码之前,我是用 C++ 编程编写代码的新手。我尝试将 txt 文件作为数据库来解决。但是我犯了这个错误我在互联网上搜索我找不到确切的答案?请知道的帮帮我。谢谢。
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void menu() {
puts("1. List the products");
puts("2. Add a new product");
puts("3. Sell the new product");
puts("4. Search by Barcode");
puts("5. Exit");
}
int main(int argc, char *argv[]) {
FILE *fProduct;
char name[20];
int quantity;
int barcode;
double price;
menu();
fProduct = fopen("Product.txt", "a+");
if (fProduct != NULL) {
while (!feof(fProduct))
{
printf("Name :");
scanf("%s" , name);
printf("Quantity :");
scanf("%d", &quantity);
printf("Barcode Number :");
scanf("%d", &barcode);
printf("Price :");
scanf("%lf", &price);
printf("Are there any product ???");
}
}
fclose(fProduct);
}
最佳答案
fclose
应用了 parameter validation assertion .
The
fclose
function closesstream
. Ifstream
isNULL
, the invalid parameter handler is invoked, as described in Parameter Validation. ...
In Debug builds, the invalid parameter macro usually raises a failed assertion and a debugger breakpoint before the dispatch function is called. ...
将您的 fclose
调用移动到检查 NULL
的 if
block 中。
关于c++ - 运行时在 C++ 上调试断言失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46920933/