gpt4 book ai didi

c++ - *** 检测到 glibc *** ./a.out : double free or corruption (out): 0xbfe69600 ***

转载 作者:塔克拉玛干 更新时间:2023-11-03 08:08:15 25 4
gpt4 key购买 nike

我正在编写一个程序来表示“学生”表。它具有属性“ID”、“名字”和“姓氏”。我做了一个二维数组,并在整个过程中放置​​了 cout 语句来检查......正确的信息存储在正确的单元格中,但我得到了一个我不认识的错误。.cpp 文件的代码是:

#include "Table1.h"
#include <sstream>
#include <iostream>
using namespace std;

Table1::Table1(){

RowPos = 1;
ColPos = 0;

for(int i=1; i<16; i++)
{
for(int j=0; j<3 ; j++)

Students[i][j] = "FakeNull"; // fill the array with Null value
}
}

string Table1::InsertStudent(string ID, string FN, string LN){

Students[0][0] = "StudentID";
Students[0][1] = "FirstName";
Students[0][2] = "LastName";


Students[RowPos][ColPos] = ID; //Assign ID to first column
ColPos++; //Move to next column
Students[RowPos][ColPos] = FN;
ColPos++;
Students[RowPos][ColPos] = LN;
ColPos++;

ColPos = 0;
RowPos++;
}

void Table1::Print(string Name){

if(Name == "students"){

for(int i=1; i<16; i++)
{
int j=0;
if(Students[i][j] == "FakeNull")
break;
else
cout<< "("<< Students[i][j]<< ",";
j++;
cout<< Students[i][j]<< ",";
j++;
cout<< Students[i][j]<< ")";

}


}
}

我的 Table1.h 是:

#include <iostream>
using namespace std;
#include <string>


#ifndef GRADE_HEADER
#define GRADE_HEADER
class Table1

private:

string Students[16][3];

string Grades[16][3];
int RowPos;
int ColPos;

public:
Table1();
string InsertStudent(string, string, string);
string InsertGrade(string, string, string, string);
void Print(string);
void Select(string, string, int);
void Select(string, string, string);
void Select(string, string, char);
void Join();
string Converter(int);


};
#endif

错误如下:

    *** glibc detected *** ./a.out: double free or corruption (out): 0xbfbdeae0 ***
======= Backtrace: =========
/lib/i386-linux-gnu/libc.so.6(+0x75ee2)[0xeadee2]
/usr/lib/i386-linux-gnu/libstdc++.so.6(_ZdlPv+0x1f)[0x9a951f]
/usr/lib/i386-linux-gnu/libstdc++.so.6(_ZNSs4_Rep10_M_destroyERKSaIcE+0x1b) [0x99099b]
/usr/lib/i386-linux-gnu/libstdc++.so.6(+0x909dc)[0x9909dc]
/usr/lib/i386-linux-gnu/libstdc++.so.6(_ZNSsD1Ev+0x2e)[0x990a4e]
./a.out[0x8049299]
/lib/i386-linux-gnu/libc.so.6(__libc_start_main+0xf3)[0xe514d3]
./a.out[0x8048a71]
======= Memory map: ========
003a0000-003ca000 r-xp 00000000 08:01 150255 /lib/i386-linux-gnu/libm-2.15.so
003ca000-003cb000 r--p 00029000 08:01 150255 /lib/i386-linux-gnu/libm-2.15.so
003cb000-003cc000 rw-p 0002a000 08:01 150255 /lib/i386-linux-gnu/libm-2.15.so
005a5000-005a6000 r-xp 00000000 00:00 0 [vdso]
007c5000-007e5000 r-xp 00000000 08:01 150250 /lib/i386-linux-gnu/ld-2.15.so
007e5000-007e6000 r--p 0001f000 08:01 150250 /lib/i386-linux-gnu/ld-2.15.so
007e6000-007e7000 rw-p 00020000 08:01 150250 /lib/i386-linux-gnu/ld-2.15.so
00900000-009d8000 r-xp 00000000 08:01 393409 /usr/lib/i386-linux gnu/libstdc++.so.6.0.16
009d8000-009d9000 ---p 000d8000 08:01 393409 /usr/lib/i386-linux gnu/libstdc++.so.6.0.16
009d9000-009dd000 r--p 000d8000 08:01 393409 /usr/lib/i386-linux gnu/libstdc++.so.6.0.16
009de000-009e5000 rw-p 00000000 00:00 0
00c13000-00c2f000 r-xp 00000000 08:01 132412 /lib/i386-linux-gnu/libgcc_s.so.1
00c2f000-00c30000 r--p 0001b000 08:01 132412 /lib/i386-linux-gnu/libgcc_s.so.1
00c30000-00c31000 rw-p 0001c000 08:01 132412 /lib/i386-linux-gnu/libgcc_s.so.1
00e38000-00fdc000 r-xp 00000000 08:01 150260 /lib/i386-linux-gnu/libc-2.15.so
00fdc000-00fde000 r--p 001a4000 08:01 150260 /lib/i386-linux-gnu/libc-2.15.so
00fde000-00fdf000 rw-p 001a6000 08:01 150260 /lib/i386-linux-gnu/libc-2.15.so
00fdf000-00fe2000 rw-p 00000000 00:00 0
08048000-0804a000 r-xp 00000000 00:19 52698567
0804a000-0804b000 r--p 00001000 00:19 52698567
0804b000-0804c000 rw-p 00002000 00:19 52698567
09df7000-09e18000 rw-p 00000000 00:00 0 [heap]
b77c9000-b77cc000 rw-p 00000000 00:00 0
b77de000-b77e3000 rw-p 00000000 00:00 0
bfbbe000-bfbdf000 rw-p 00000000 00:00 0 [stack]
Aborted (core dumped)

最佳答案

I get an error I don't recognize

该错误仅表示您已损坏堆。

最常见的破坏堆的方法是:

  • 在分配结束后写入
  • 释放你没有分配的内存
  • 两次释放一些东西。

发现错误的最快方法是在 Valgrind 下运行二进制文件.

关于c++ - *** 检测到 glibc *** ./a.out : double free or corruption (out): 0xbfe69600 ***,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22573292/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com