好的,伙计们,我已经尝试了我能想到的一切。我将一个文件名传递给这个函数。一点上下文:hash_table 是一个已经初始化并填充了键对的向量,键对的“值”部分是一个具有字段“bucket_size”的链表。当我使用 cout 检查这些字段是否实际被访问时,它们是;甚至调试器也将它们列为已归档到输出流中。我有 flush() 和 close() 在那里,但它没有向文件写入任何内容。返回 true,表示流中没有错误。有人有什么想法吗?
string line;
std::ofstream ofs;
if(ofs.is_open())
ofs.close();
ofs.open(filename);
if (ofs.is_open())
{
cout << "File Opened" << endl;
for (double i = 0; i < hash_table.capacity(); ++i)
{
ofs << "Bucket Number " << i;
if (hash_table[i].value != NULL)
ofs << " Bucket Size: " << hash_table[i].value->bucket_size << endl;
else
ofs << " Bucket Size: 0" << endl;
ofs.flush();
}
cout << "closing file stream" << endl;
ofs.flush();
ofs.close();
if (ofs.good())
return true;
else
return false;
}
else
{
cout << "File not opened" << endl;
return false;
}
}