分段故障核心使用 IF流转储
segmentation fault core dumped using ifstream
我写了一个代码来读取一个文本文件并对其进行一些处理。它在我自己的PC和另一个Linux系统上正常工作。但是,当我在不同的 Linux 系统上运行它时,我收到"ifstream"命令的"分段错误(核心转储("错误。我检查了文本文件,如果它太小(例如两行(,cose 工作正常,但是当文件较大(例如 20 行(时,它会崩溃并出现分段错误错误。
导致错误的代码段:
int ExtractFragments(int fragmentLength, int overlappingResidues)
{
string line = "", lines = "", interfaceFileName = "";
ifstream interfaceList("tempInterfaceList.txt");
if (interfaceList)
{
bool errFlag = false;
while (getline(interfaceList, interfaceFileName))
{
cout << endl << "interfaces/" << interfaceFileName;
ifstream interfaceFile("interface.txt"); //This line crashes
if (interfaceFile)
cout << "nHello";
}
}
return 0;
}
任何想法为什么这个ifsream会导致分段错误以及如何解决它? 谢谢!
我怀疑 对同一流的并发访问可能会引入数据争用。 您正在以输入模式打开一个文件 while 循环在那里,您必须处理异常
int ExtractFragments(int fragmentLength, int overlappingResidues)
{
ifstream interfaceList("tempInterfaceList.txt");
interfaceList.exceptions ( std::ifstream::failbit | std::ifstream::badbit );
try
{
if ( interfaceFile.fail() )
{
return -1;
}
bool errFlag = false;
while (getline(interfaceList, interfaceFileName))
{
cout << endl << "interfaces/" << interfaceFileName;
ifstream interfaceFile("interface.txt"); //This line crashes
if (interfaceFile)
cout << "nHello";
}
}
catch(std::ifstream::failure &FileExcep)
{
cout<<FileExcep.what()<<endl;
return -1;
}
catch(...)
{
cout<< "other exception thrown"<<endl
return -1;
}
return 0;
}
相关文章:
- 分段故障(堆芯转储)矢量
- Cppcheck生成xml转储文件
- 如何找出GDB的SIGTRAP核心转储的根本原因
- C++映射分割错误(核心转储)
- 在c++中初始化矩阵时出现分段错误(核心转储)
- 在c++中键入向量中的所有值后,得到分段错误(核心转储)
- 浮点异常(核心转储)#694457
- 分段错误(核心转储)但无法弄清楚
- 链接到libkcapi时没有核心转储
- 检测到堆栈粉碎:已终止 中止(核心已转储)
- 正在处理故障(堆芯转储)
- 分段错误(核心转储) - 使用 SavedModel 的 Tensorflow C++ API 进行推断
- 我不知道为什么这段代码会让核心被转储?
- C++运行时错误与快速排序算法抛出堆栈转储错误
- 在基数排序中,我得到 munmap_chunk():无效指针和中止(核心转储).为什么?
- C++指针无法在函数外部传递值和分段错误(核心转储)错误
- cygwin_exception::open_stackdumpfile:将堆栈跟踪转储到 class4.exe.sta
- C++快速将 int 数组内容转储到文本文件中
- 合并排序:分段错误核心转储
- WinDbg 不显示某些小型转储文件的完整堆栈跟踪