未知C++错误:致命错误:glibc检测到无效的stdio句柄

Unknown C++ error: Fatal error: glibc detected an invalid stdio handle

本文关键字:无效 stdio 句柄 glibc C++ 错误 致命错误 未知 检测      更新时间:2023-10-16

我一直在互联网上搜索,试图了解我为什么会出现这个错误,但我只在我不熟悉的其他编程语言或从未使用过的代码中见过这种情况。

我正在为一项学校作业编写一个快速排序程序,一切都很顺利,直到我决定将中值气泡排序算法合并为一个辅助函数。

int* QS::MedianSort(int left, int middle, int right) {
cout << "starting MedianSort...n";////////////
int temp;
static int sort [] = { left, middle, right };
do {
if (sort[0] <= sort[1] && sort[1] <= sort[2]) {
break;
}
else if (sort[1] < sort[0]) {
temp = sort[1];
sort[1] = sort[0];
sort[0] = temp;
}
else if (sort[2] < sort[1]) {
temp = sort[2];
sort[2] = sort[1];
sort[1] = temp;
}
} while(true);
cout << "...returning sort from Median Sortn";//////////
return sort;
}

它在我的分区算法中的实现示例:

int *temp;
int tempInt;
temp = MedianSort(*(array + left), *(array + pivotIndex), *(array + right));
*(array + left) = *(temp + 0);
*(array + pivotIndex) = *(temp + 1);
*(array + right) = *(temp + 2);
tempInt = *(array + pivotIndex); 
*(array + pivotIndex) = *(array + left);
*(array + left) = tempInt;

array是指向我正在快速排序的数组的指针,left是传递给分区函数的最小索引,right是最大索引。

当我编译代码时,它没有问题,但一旦我运行可执行文件,我就会在控制台中收到以下错误:

Fatal error: glibc detected an invalid stdio handle
Aborted

我不明白为什么,因为它以5个输入文件中的第3个结束,但甚至没有开始第4个文件。(我知道这一点,因为我在几乎每个函数的开头都有cout语句来向我展示它的进展。(

此外,到目前为止,main.cpp已经成功地遍历了所有文件。

编辑:我正在使用-g -std=c++11进行编译

此外,到目前为止,main.cpp已经成功地遍历了所有文件。

你确定吗?这个问题通常与文件有关。你应该提供它或文件处理中涉及的范围,看看问题是什么

我认为这行有问题:

static int sort [] = .....

如果我理解正确的话,静态变量只会初始化一次(第一次调用函数(。