【发布时间】:2019-03-14 06:43:26
【问题描述】:
这些是我的结构:
struct Artist
{
string Name;
string CountryOfOrigin;
};
struct Time
{
int Minutes;
int Seconds;
};
struct Song
{
string Title;
Artist ArtistDetails;
Time LengthOfSong;
};
还有我的功能:
void LoadSongDataFromFile(Song s[])
{
string inputFile, title, name, country;
int minutes, seconds;
cout << "Please enter the input file name: ";
cin >> inputFile;
ifstream input;
input.open(inputFile);
int count = 0;
while (input >> title)
{
s[count].Title >> title;
s[count].ArtistDetails.Name >> name;
s[count].ArtistDetails.CountryOfOrigin >> country;
s[count].LengthOfSong.Minutes >> minutes;
s[count].LengthOfSong.Seconds >> seconds;
count++;
}
}
我在这三行中遇到错误:
s[count].Title >> title;
s[count].ArtistDetails.Name >> name;
s[count].ArtistDetails.CountryOfOrigin >> country;
说没有操作符 >> 匹配这些操作数。 操作数类型为:std::string >> std::string
我试图放入结构数组的数据也来自一个包含以下信息的文本文件:
完美
艾德希兰和碧昂丝
英格兰
4
23
如果重要的话,文本文件名是 songdata.txt。非常感谢任何帮助!
【问题讨论】: