【发布时间】:2016-12-11 11:23:52
【问题描述】:
我正在尝试查找这段代码中有什么问题。它说错误:[Error] no match for 'operator>>' in 'inputData >> Player[i].AthleteType::firstName' 表示该行:
inputData >> Player[i].firstName;
谁能告诉我这是什么意思?如果这是从如下所示的文件中读取数据的正确方法:
Peter Gab 2653 Kenya 127
Usian Bolt 6534 Jamaica 128
Other Name 2973 Bangladesh -1
Bla Bla 5182 India 129
Some Name 7612 London -1
//this is the structure
struct AthleteType
{
string firstName[SIZE];
string lastName[SIZE];
int athleteNumber[SIZE];
string country[SIZE];
int athleteTime[SIZE];
};
void readInput(int SIZE)
{
AthleteType Player[SIZE];
ifstream inputData("Athlete info.txt");
int noOfRecords=0;
for (int i=0; i < SIZE; i++, noOfRecords++)
{
inputData >> Player[i].firstName;
inputData >> Player[i].lastName;
inputData >> Player[i].athleteNumber;
inputData >> Player[i].country;
inputData >> Player[i].athleteTime;
}
for (int i=0; i < noOfRecords; i++)
{
cout << "First Name: " << Player[i].firstName << endl;
cout << "Last Name: " << Player[i].lastName << endl;
cout << "Athlete Number: " << Player[i].athleteNumber << endl;
cout << "Country: " << Player[i].country << endl;
cout << "Athlete Time: " << Player[i].athleteTime << endl;
cout << endl;
}
}
【问题讨论】:
-
@StoryTeller JF 正在尝试输入字符串数组。
-
这
inputData >> Player[i].firstName;不应该是inputData >> Player.firstName[i];吗?除此之外,结构看起来很荒谬。其余代码也是如此。 -
@πάνταῥεῖ 很好 - 这是昨天的
char[]! @Jannatul 进展非常迅速。 -
@JackDeeth 我总是很好。告诉别人真相不再被认为是很好了吗?
-
谢谢@Jack!一旦我弄清楚代码将如何工作,我肯定会这样做:)