运行时错误:_block_type_is_valid(phead-nblockuse)
Runtime error: _block_type_is_valid(phead- nblockuse)
首先,我将向您展示我的代码。
std::ifstream file("accounts/22816.txt");
if(file){
char *str[50];
int count=0;
str[0] = new char[50];
while(file.getline(str[count], 50)){
count++;
str[count] = new char[50];
}
for(int i=0;i<count;i++){
std::cout << str[i] << std::endl;
}
delete[] str; // Here is the problem
}
上一个代码的行为是:
- 逐行阅读文本文件的内容
- 保存2D阵列项目中的每一行
- 打印2D阵列的项目
- 最后,从内存中删除数组<lt;CCD_ 1
当测试我的应用程序时,总是给我运行时错误消息_block_type_is_valid(phead- nblockuse).
我知道这个问题,因为这个delete[] str;
str
是一个指针数组,每个指针指向一个动态分配的数组。
您需要对它进行循环,并对每个元素调用delete []
。
for(int i=0; i < count; ++i){
delete [] str[i];
}
注意:我已经为OP提供了一个使用std::vector
、std::string
和std::getline
的示例。
相关文章:
- 调试断言失败 BLOCK_TYPE_IS_VALID (pHead->nblockuse) 从解构函数
- _BLOCK_TYPE_IS_VALID(pHead->nBlockUse) "return 0"后
- std::shared_ptr _BLOCK_TYPE_IS_VALID(pHead->nBlockUse) 更改指针时
- BLOCK_TYPE_IS_VALID(pHead->nBlockUse) 发生在主返回
- BLOCK_TYPE_IS_VALID(pHead -> nBlockUse) 错误
- 调试断言失败!表达式:_BLOCK_TYPE_IS_VALID(pHead->nBlockUse)
- 表达式:_BLOCK_TYPE_IS_VALID(pHead->nBlockUse) 错误
- 类中的赋值运算符,_ASSERTE(_BLOCK_TYPE_IS_VALID(pHead->nBlockUse));
- _BLOCK_TYPE_IS_VALID(pHead->nBlockUse error Visual Studio 2012
- _BLOCK_TYPE_IS_VALID(pHead->nBlockUse) 错误
- _block_type_is_valid phead- nblockuse on delete command
- 运行时错误:_block_type_is_valid(phead-nblockuse)
- _block_type_is_valid(phead- nblockuse) 当使用 delete[] 时
- 为什么我会收到_Block_Type_Is_Valid(pHead->nBlockUse)错误?
- _block_type_is_valid(phead- nblockuse)因为删除命令
- 使用 ASSERT " _BLOCK_TYPE_IS_VALID(pHead->nBlockUse) "调整动态分配的内存C++的大小
- C++ 调试断言失败_BLOCK_TYPE_IS_VALID(pHead->nBlockUse)
- _BLOCK_TYPE_IS_VALID(pHEAD->nBlockUse) 错误
- _Block_Type_Is_Valid (pHead->nBlockUse) 删除堆栈内存?
- 调试断言失败!表达式:_BLOCK_TYPE_IS_VALID(pHead->nBlockUse) 在程序中结束