c++ - 错误: glibc detected when using vector

标签 c++ linux vector

我在代码中使用了数组,现在我将它们更改为 vector我收到这些错误(在 Linux 中):

glibc detected *** double free or corruption

glibc detected malloc memory corruption

我的代码太长了,无法粘贴到这里,这是我的使用方式vector :

声明:

 vector:vector<double>x;//i didnt define anysize for vector

用于在其中插入值:

x.insert(x.begin()+i,i)

使用元素:

 x.at(i)

就这个。

您对这个问题有何看法? <罢工>?
另外我不知道什么时候应该在 vector 中使用迭代器,我不应该在这里使用它吗? <罢工>?

TIA

最佳答案

这只是一个疯狂的猜测(没有看到代码),但是您是否只是从中替换了您的数组:

// some code
double *array = new double[ 50 ];
// use array somehow
delete[] array;

进入此:

// some code
std::vector< double > array;
// use array somehow
delete [] &array[0];

最好的选择是使用 valgrind 运行程序,它应该准确地告诉您问题出在哪一行。

关于c++ - 错误: glibc detected when using vector,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6896239/

相关文章:

c++ - 当我返回指向结构的指针 vector 时出现段错误

c++ - 对结构 vector 进行排序

c++ - 是否有明确说明模板类型的原因?

c++ - 检查 C 风格数组是否等于其他(编译时)数组

python - 有没有办法在 Arago 项目上安装 Pypy3?

r - 如何解决软件包安装过程中的 'libRblas.so: No such file or directory'?

c++ - 如何在 C++ 中生成给定数组的子集?

c++ - 如何在搜索中不使用 std::map 的自定义比较功能(map::find)?

c++ - 指向第一个元素的指针的地址

linux - Shell 编程 printf %s