My code below kept running into segmentation fault error and i can't seem to figure out why. Help pls~~ My goal is to read a folder and all of its subfolders to find all files ending with extension ".txt" so i am using boost's recurisve directory iterator to help achieve the task. This issue arrived suddenly as my code was running fine last week.
test.cpp:
#include <sstream>
#include <iostream>
#include "/home/dj/boost_1_65_1/boost/filesystem.hpp"
using namespace std;
int main()
{
using namespace boost::filesystem;
recursive_directory_iterator end;
for (recursive_directory_iterator it("./"); it != end; ++it)
{
std::cout << *it << endl;
}
return 0;
}
i am running on Linux and i compile my test.cpp with boost 1.65 as static :
g++ -g -I /home/dj/boost_1_65_1 test.cpp -static -static-libgcc -o delete -static-libstdc++ -std=c++11 -L/home/dj/boost_1_65_1 -lboost_filesystem -lboost_system
with gdb and some cout i found that error came from the line below.
for (recursive_directory_iterator it("./"); it != end; ++it)
somehow when i call for "recursive_directory_iterator", my system crashes giving this error
Program received signal SIGSEGV, Segmentation fault.
0x00000000004f1c8b in memcpy ()
the exact same error persists even if i reduce the code to
int main()
{
using namespace boost::filesystem;
recursive_directory_iterator it("./");
return 0;
}
Aucun commentaire:
Enregistrer un commentaire