二叉树程序出错?不会编译?

Error in Binary Trees Program? Won't Compile?

#include<iostream>
#include<string>
#include<fstream>
using namespace std;

struct node
{
  char data;
  int count;
  node * left;
  node *right;
};

//to create a new node 
node* create_node(char ch)
{
  node *new_node=new node;
  new_node->data=ch;
  new_node->count=1;
  new_node->left=NULL;
  new_node->right=NULL;
  return new_node;
}

//function to insert a data in new node
node * insert_data(node *root,char ch)
{
  if (root==NULL) {
    return create_node(ch);
  }

  if (ch==root->data) {
    (root->count)++;
    return root;
  }

  if (ch<root->data)
    root->left=insert_data(root->left,ch);
  else 
    root->right=insert_data(root->right,ch);

  return root;
}

//preorder traversal of BST(binary search tree)
void display(node* temp)    
{
  if (temp==NULL)
    return;
  cout<<temp->data<<" ";
  cout<<temp->count<<endl;
  display(temp->left);
  display(temp->right);
}

int main()
{ 
  string file_name;char ch;
  cout<<"enter file name\n";
  cin>>file_name;
  fstream file(file_name,ios::in);
  node* root;
  root=NULL;
  //reading characters from a file
  while (file>>ch&&file!='[=10=]')
    {    
      root=insert_data(root,ch);    
    }

  file.close();
  display(root);
  return 0;    
}

请耐心等待,我将发布错误和项目描述。

错误第 53 行:错误:没有匹配函数来调用 `std::basic_fstream >::basic_fstream(std::string&, const std::_Ios_Openmode&)'

项目描述:完整项目描述:

在此作业中,您将使用二叉搜索树来收集有关文本文件的信息。 这应该测试二叉搜索树的使用、基本文件处理和 string/char 操作。 背景:在密码学中,尝试破解密码的一种方法是计算 每个字母,字母对组合的数量,3个字母组合的数量 等等。也就是说,字母的任何特定子序列的数量。 例如,在字符串“aadabcdaa”中,它具有以下子序列频率

一:5

b: 1

c: 1

d: 2

aa: 2

广告:1

大: 2

ab: 1

公元前:1

CD: 1

aad : 1

等等。 您的程序将打开一个文件,该文件计算最多出现连续字母“k”的次数,因此如果 用户输入 k=4,你将存储所有连续字母序列的数量,最多为 4.

描述:您的程序应该以提示用户输入文件名开始。然后,打开那个 文件并根据需要使用它来执行以下操作:使用存储在每个节点的二叉搜索树 一个字符串和它找到的那个节点的数量。然后,通过给定的文件 (文本文件),从第一个字母开始,把它放到树上,计数为 1。然后得到下一个 文件中的字符,将其推送到树上,等等。如果您尝试添加一个节点 已经添加(例如,将“a”推到已经有“a”的树上,递增 该节点的计数。 完成后,再次浏览文件并获取所有连续出现的 2 个字母 并将它们推到树上。同样,如果有匹配项,则增加计数。 重复整个过程,直到达到“k”长序列。 注意:当然,如果您愿意,您也可以将所有这些步骤结合起来,这样它只需要一个步骤 读取文件。

输出:程序完成后,对树进行中序遍历,输出数据 以下格式: 一:27

aa: 6

aaa: 3

等 表示字母 a 被找到 27 次,序列“aa”被找到 6 次,依此类推。 额外的复杂性:由于在代码中使用误导性空格或保留空格很常见 完全空格,您的代码应该忽略消息中的任何空格。简单处理 字母字符及其顺序。因此,例如,序列“a a”仍然有效 作为连续的“aa”。您接收的文件将仅包含字母字符和空格。 它可能有也可能没有结束符,但是在任何一种情况下你都应该忽略它们,因为你 为空间做。 我建议你通过让它存储单字母出现的统计数据来开始这项作业 然后尝试使用多字母序列。这样你就知道树的操作和遍历 在你搞乱解析字符串之前工作正常。 错误处理:您的程序应该处理所有合理的文件错误。所以如果文件没有 存在或无法读取,应该输出错误信息。

改变

fstream file(file_name,ios::in);

fstream file(file_name.c_str(),ios::in);

您可能使用 C++ 98/03 编译

根据cplusplus,在C++98中,fstream的构造函数是

explicit fstream (const char* filename,
              ios_base::openmode mode = ios_base::in | ios_base::out);