这是我得到的错误:
ambiguous overload for ‘operator>>’ in ‘contestantsInputFile >> contestantName’|
我正在尝试通过引用将文件传递给函数,以便将名称读入名为竞争者名称的变量中。
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
string contestantName = "";
string contestantName(ifstream &);
int main()
{
ifstream contestantsInputFile;
contestantsInputFile.open("contestants_file.txt");
contestantName(contestantsInputFile);
}
string contestantName(ifstream &contestantsInputFile)
{
contestantsInputFile >> contestantName; //this is the line with the error
return contestantName;
}