我有一个应该写入下面定义的gml文件的类。该类有一个方法来完成写入。如果调用该函数,则在主函数返回时获得核心转储。我可以创建类的对象没有问题,它只发生在write函数被调用时。该函数也没有错误地返回,程序的其余部分运行。
GML作家:
class GMLWriter {
public:
void write(List<User*> usr, const char* filename);
};
void GMLWriter::write(List<User*> usr, const char* filename)
{
cout << "Filename: " << filename << endl;
ofstream outfile;
outfile.open(filename);
if (!outfile.is_open())
cout << "Couldn't open the file..." << endl;
outfile << "graph [n";
// Write user data
for (int n = 0; n < usr.size(); n++) {
cout << "Writing node..." << endl;
outfile << "node [n";
outfile << "id " << usr[n]->getID() << "n";
outfile << "name "" << usr[n]->getName() << ""n";
outfile << "age " << usr[n]->getAge() << "n";
outfile << "zip " << usr[n]->getZip() << "n";
outfile << "]n";
}
// Write associations
for (int n = 0; n < usr.size(); n++) {
List<int> tList = usr[n]->getFriends();
cout << "Writing edge..." << endl;
//List<int> tempL = usr[n]->getFriends();
for (int i = 0; i < tList.size(); i++) {
outfile << "edge [n";
outfile << "source " << usr[n]->getID() << "n";
outfile << "target " << tList[i] << "n";
outfile << "]n";
}
}
outfile << "]"; // end graph
cout << "End function" << endl;
outfile.close();
}
User只是包含要写入文件的变量,这些方法工作得很好。
我花了几个小时在调试器上,还没能找到问题。如有任何帮助,我将不胜感激。
谢谢!
尝试查看核心转储:http://www.network-theory.co.uk/docs/gccintro/gccintro_38.html