在boost文件系统中使用目录\u项时出错 我开始在Ubuntu上使用代码块在C++程序中使用Boost库。
我在操作文件时遇到问题,以下代码返回分段错误:在boost文件系统中使用目录\u项时出错 我开始在Ubuntu上使用代码块在C++程序中使用Boost库。,boost,filesystems,Boost,Filesystems,我在操作文件时遇到问题,以下代码返回分段错误: #include <iostream> #include <boost/filesystem.hpp> using namespace std; int main() { boost::filesystem::path my_file("/home/malinou/workspace/grunbaum2/grunbaum/Bases/config.txt"); cout << "my_file
#include <iostream>
#include <boost/filesystem.hpp>
using namespace std;
int main()
{
boost::filesystem::path my_file("/home/malinou/workspace/grunbaum2/grunbaum/Bases/config.txt");
cout << "my_file path : " << my_file.string() << endl;
cout << "my_file exists : " << boost::filesystem::exists(my_file.string()) << endl;
cout << "my_file path : " << my_file.string() << endl;
return 0;
}
你知道为什么调用exists()
函数后我的_文件似乎会导致问题吗
(注意:当我调用
is\u regular\u file()
函数而不是exists()
函数时,问题是一样的。)最后回答我的问题,这似乎是由于我使用的IDE导致的链接错误。我用相同的文件创建了一个新项目,它工作得非常好…奇怪
无论如何,谢谢大家的帮助 对不起,无法复制。您的代码在我的机器上运行正常。您确定这是您实际使用的代码吗?提示:如果您使用
-g
编译,然后使用gdb executable
运行您的程序run
,您应该可以准确地看到哪里出了问题。是的,这是我实际使用的代码,它让我感到不舒服,因为这段代码太简单了,我不明白为什么会出问题:/I我已经有了调试的-g标志,但我不明白您的“gdb executable…run”命令。使用可执行文件启动gdb:gdb yourprog
。然后等待所有的东西被打印出来。然后gdb提示符会向您打招呼;在那里,键入run
,然后按回车键
my_file path : /home/malinou/workspace/grunbaum2/grunbaum/Bases/config.txt
my_file exists : 1
Segmentation fault (core dumped)
Process returned 139 (0x8B) execution time : 0.093 s
Press ENTER to continue.