c++ - 错误在 `./2' : free(): invalid pointer: 0x000000000096044c *** Aborted (core dumped)

标签 c++ arrays pointers dynamic

我是 C++ 的新手,当我删除指向整数数组的指针时,我的程序出现了这个错误。这是我的部分代码。

int *list=new int[20]; 

ifstream in;
in.open(xxx);
for(a = 0; a < 10; a++){
in >> *list
list++;}

delete[] list;

list = NULL;

最佳答案

list++ 删除列表; ?

您需要返回并再次查看指针等。通过执行 list++,您正在更改 list 的值,因此当您说 delete [] list 时,该值不是您分配的值。

关于c++ - 错误在 `./2' : free(): invalid pointer: 0x000000000096044c *** Aborted (core dumped),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35471820/

相关文章:

c++ - 将 char[][] 转换为 char**

c - 使用for循环分配内存

c++ - 将 OpenMPI 或 MPICH 与 Boost MPI 一起使用 Win 和 Linux 机器

c++ - 定义 VTKPolyDataMapper 的中心

c++ - 在 C++ 中使用 double/float 类型时如何设置精度

ios - 在 iOS 中创建多维数组

c++ - 当一个变量被定义并且它似乎被这样识别时,什么会导致 "C2065: undeclared identifier"?

javascript - 按对象属性对 javascript 对象数组进行排序

C 将文本文件中的数字读入数组并将数字用于其他功能

c++ - char 数组的 strlen 大于其大小。如何避免?