我需要在读取文本文件的搜索二叉树中插入数据。当我在数据之间使用空格时它可以工作,但如果我像我想要的那样使用逗号它就不起作用。例如,我希望我的文本文件如下所示:
New-York,c3,Luke
London,c5,Nathan
Toronto,c1,Jacob
  ...
我的文本文件现在看起来像这样:
New-York c3 Luke
London c5 Nathan
Toronto c1 Jacob
  ...
我还希望我的程序不要认为空格意味着它需要查看下一个数据,只能使用逗号。
这就是我的代码的样子:
void fillTree( BinarySearchTree *b)
{
    ifstream file;
    file.open("data.txt");
    string city;
    string tag;
    string name;
    Person p;
    if(!file) {
        cout<<"Error. " << endl;
    }
    while(file >> city >> tag >> name)
    {
        p.setCity(city);
        p.setTag(tag);
        p.setName(name);
        cout << p.getCity() << " " << p.getTag() << " " << p.getName() << endl;
        (*b).insert(p);
    }
    file.close();
}
我需要在代码中进行哪些更改,以便可以使用逗号而不是空格?我觉得它在带有逗号而不是空格的文本文件中看起来更整洁。我很确定我需要在这段代码中编辑一些东西,但如果它可能在其他地方,请告诉我。