-1
我試圖尋找這段代碼中的錯誤。它說的錯誤:[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進展非常迅速。 –