我目前有一个项目,是我运行一个带有数千个名称的文本文件并将其放入二进制存储树中。遇到此错误,绊脚石:

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);
}

08-24 15:05