未知C++错误:致命错误:glibc检测到无效的stdio句柄
Unknown C++ error: Fatal error: glibc detected an invalid stdio handle
我一直在互联网上搜索,试图了解我为什么会出现这个错误,但我只在我不熟悉的其他编程语言或从未使用过的代码中见过这种情况。
我正在为一项学校作业编写一个快速排序程序,一切都很顺利,直到我决定将中值气泡排序算法合并为一个辅助函数。
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 [] = .....
如果我理解正确的话,静态变量只会初始化一次(第一次调用函数(。
相关文章:
- Openssl 1.1.1d无效使用不完整的类型"struct dsa_st"
- 无法访问嵌套类.类的使用无效
- 如果用户输入无效,如何使用字符串变量-C++重复输入命令
- 如何解决错误:SCIP C++中的 SCIP 阶段无效 <10>
- 在没有参数列表的情况下使用模板名称"Event"无效,模板问题
- FFMPEG配置文件级别id大小无效
- 错误:从"int"到枚举c++的转换无效
- 如何修复此错误:className::className的无效使用
- 为什么将值返回函数传递给重载=运算符对运算符函数有效,而对其他运算符无效
- C++-模板嵌套类的引用初始化无效
- 错误:无效的预处理指令 #i 的意思是 #if?
- 多维数组 C++ 中数组下标的类型"int[int]"无效
- 在 C++ 中使用正则表达式错误时出现问题 括号表达式中的范围无效
- 与 stdio 同步是否使程序 I/O 非交互式?
- 从 'int' 到 'int*' CPP 的转换无效
- 如何接受 [ENTER] 键作为无效输入并发送错误消息
- 由于无效的 ValidateRgn() 子窗口不会收到WM_PAINT消息
- C++ PTHREADS - 无效转换无效*(*)()到无效*(*)(无效*)
- 未知C++错误:致命错误:glibc检测到无效的stdio句柄
- 如何替换/忽略 C stdio.h getline() 中的无效 Unicode/UTF8 字符