我有一个BST数据库,我必须将其导出到.CSV文件。我可以得到它来导出第一条记录。我如何让它循环直到导出整个数据库。
void get(NodeActor* node, ofstream myfile)
{
if(node==NULL)
return;
myfile << "Year , Award, Winner, name, film"<< endl;
myfile << node->year << "," << node->award << "," << node->winner << "," << node->name << "," << node->film<< endl;
get(node->left,myfile);
get(node->right,myfile);
}
void ActorBST::ExportToCSV(NodeActor *node)
{
string fileName;
cout << "File Name(include .csv): ";
cin >>fileName;
ofstream myfile;
myfile.open (fileName);
myfile << "Year , Award, Winner, name, film"<< endl;
myfile << node->year << "," << node->award << "," << node->winner << "," << node->name << "," << node->film<< endl;
myfile.close();
}
答案 0 :(得分:0)
我想您只需要在get
方法内调用ExportToCSV
函数。
您的get
方法已经在处理递归,因此只要您将顶部节点传递到ExportToCSV
,它就可以工作。
void ActorBST::ExportToCSV(NodeActor *node)
{
string fileName;
cout << "File Name(include .csv): ";
cin >>fileName;
ofstream myfile;
myfile.open (fileName);
get(node, myfile);
myfile.close();
}
也许您想将get
用作ActorBST
类的方法,但这不是强制性的。