2012-05-07 4 views
0

私は現在何千もの名前のテキストファイルを実行してバイナリストレージツリーに配置しているプロジェクトがあります。このエラーにつまずきをヒット:バイナリストレージツリーfstreamのエラー

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 

私は誰かが私には根本的な問題を説明するのに役立つことを願って。

ありがとうございます。

ジョシュ

編集:あなたのwrite機能で

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

どこダソースコードですか? – mfontanini

答えて

1

:あなたはofstreamをコピーすることはできません。参照渡し。その後、再び、あなたは決して使用体内のnameOut関数の引数には思えない、なぜだけでなく、それを完全に省略します。

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

ああ、ありがとう。コールにパラメータが必要なので、唯一の問題は私の現在のところです。 binaryTreeStorage1.write(out8); –

+0

@ジョシュ:まあ、そこからも取り除いてください!あるいは 'std :: ofstream&'を関数に渡します。 –

+0

これは割り当てであり、mainメソッドクラスを不幸に変更することはできません。私は今何をすべきか知っていると思う、助けてくれてありがとう。 –