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

时间:2019-11-19 06:56:22

标签: c++ data-structures error-handling

我一直在Internet上进行搜索,以尝试理解为什么会出现此错误,但是我只有在我不熟悉或从未使用过的代码的其他编程语言中看到过此错误。

我正在为学校分配一项快速排序程序,并且一切进展顺利,直到我决定将中位数气泡排序算法合并为一个辅助函数。

<ion-image>

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

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 Sort\n";//////////
    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

我不明白为什么,因为它以5中的第3个输入文件结尾,但是甚至没有启动第4个文件。 (我之所以知道这是因为我几乎在每个函数的开头都带有Fatal error: glibc detected an invalid stdio handle Aborted 语句来向我展示它的作用。)

此外,cout到目前为止已经成功浏览了所有文件。

编辑: 我正在使用main.cpp

进行编译

2 个答案:

答案 0 :(得分:1)

<块引用>

此外,到目前为止,main.cpp 已成功浏览所有文件。

你确定吗?此问题通常与文件有关。您应该提供它或文件处理涉及的范围以查看问题所在。

答案 1 :(得分:0)

我认为这行有问题:

static int sort [] = .....

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