这些是我的结构:
结构艺术家{ string名称; string CountryOfOrigin;
};
结构时间{ int分钟; int秒;};
结构歌{ 字符串标题; 艺术家艺术家详细信息; …
该 >> 运算符有两个含义:
>>
后者的含义在这里使用。如您所见,定义说“从流”和“到对象”。
在你的代码中你打电话给 >> 运算符读取“从字符串” s[count].Title 到另一个字符串 title 。
s[count].Title
title
预定义有许多变体 >> 运营商。它们都有一个流作为第一个操作数。因此,要使用它们,请使用 std::cin >> s[count].Title 。
std::cin >> s[count].Title
正如在另一个答案中提到的那样 >> 操作员在第一个单词后停止复制。因此最好使用 std::getline(std::cin, s[count].Title) 。
std::getline(std::cin, s[count].Title)
您可以使用 = 运算符分配值。
=
input >> minutes; s[count].LengthOfSong.Minutes = minutes;
或直接读入结构:
input >> s[count].LengthOfSong.Minutes;
读书 >> 从输入中读取一个单词,因此它只适用于您的数字。要阅读完整的一行(字符串),请使用 的std ::函数getline 。