Segfault is a runtime error. It is usually caused by pointers that don't point to anything. I can't say what is the problem here, though. You need to find at which point your program breaks. The way to do that sort of depends on the tools you have. The most simple one is to add cerr << "something\n"; at several places in your code and see which of them don't get executed. If you can't see the console when segfault happens, do the same with a file.