[英]Algorithm Library Usage
I am trying to complete a homework assignment I have, which needs to be completed using only the algorithm library in c++, without any custom loops of any sort.我正在尝试完成我的家庭作业,该作业需要仅使用 c++ 中的算法库完成,无需任何类型的自定义循环。 I need to populate a string type vector called m_Players from class Player, from an input file that contains a couple of names, and I am having trouble identifying which functions I need to use from the algorithm library to achieve that, and how to syntactically use them to reach my goal.
我需要从包含几个名称的输入文件中填充 class Player 中名为 m_Players 的字符串类型向量,但我无法从算法库中识别出需要使用哪些函数来实现这一点,以及如何在语法上使用他们达到我的目标。
std::vector<Player> m_Players;
void Glicko::LoadPlayers(std::istream& is)
{
// TODO Load the m_Players variable without using a custom loop
}
You may want to consider using an std::istream_iterator
.您可能需要考虑使用
std::istream_iterator
。 https://en.cppreference.com/w/cpp/iterator/istream_iterator https://en.cppreference.com/w/cpp/iterator/istream_iterator
This would allow you to iterate over Player
objects read from the input stream.这将允许您遍历从输入 stream 读取的
Player
对象。 Since this is a homework assignment, I won't post explicit code, but hopefully the pointer is helpful.由于这是一项家庭作业,因此我不会发布明确的代码,但希望指针对您有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.