gpt4 book ai didi

c++ - 二叉存储树 fstream 出错

转载 作者:行者123 更新时间:2023-11-28 08:04:50 31 4
gpt4 key购买 nike

我目前有一个项目,我运行一个包含数千个名称的文本文件并将它们放入二进制存储树中。碰到这个错误的绊脚石:

error C2248: 'std::basic_ios<_Elem,_Traits>::basic_ios' : cannot access private member declared in class 'std::basic_ios<_Elem,_Traits>'    c:\program files (x86)\microsoft visual studio 10.0\vc\include\fstream  1116

希望有人能帮我解释一下根本问题。

提前致谢。

乔希

编辑:

BinaryTreeStorage::BinaryTreeStorage(void) : root(NULL)
{

}

BinaryTreeStorage::~BinaryTreeStorage(void)
{

}

void BinaryTreeStorage::insert(string &input, TreeNode *&root)
{
if(root != NULL)
{
root -> name = input;
root -> left = NULL;
root -> right = NULL;
}

else if (input < root -> name)
{
insert(input, root -> left);
}
else
{
insert(input, root -> left);
}
}

string BinaryTreeStorage:: writeToTree(TreeNode *&root)
{
if(root ->left != NULL)
{
writeToTree(root ->left);
}
return root->name;
if (root->right != NULL)
{
writeToTree(root);
}
}

void BinaryTreeStorage::write(ofstream nameOut)
{
cout << "Writing out bst names" << endl;
writeToTree(root);
}

void BinaryTreeStorage::read(ifstream& nameIn)
{
cout<< "Reading in bst" << endl;
string name;

for (int i = 0; i < numberOfNames; i++)
{
nameIn >> name;
insert (name, root);
}
}

最佳答案

在您的write 函数中:您不能复制ofstream。通过引用传递它。话又说回来,你似乎从来没有在正文中使用 nameOut 函数参数,所以为什么不完全省略它呢:

void BinaryTreeStorage::write()
{
cout << "Writing out bst names" << endl;
writeToTree(root);
}

关于c++ - 二叉存储树 fstream 出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10482180/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com