如何在不手动输入的情况下适当阅读用户输入?
我一直在尝试弄清楚如何在用户输入中阅读,而不必手动输入每个示例。我正在建造一款石头游戏,应该使我熟悉循环链接的列表。我必须手动输入这样的示例才能实现输出。是否有另一种替换的方法,并阅读示例文本
?
#include <iostream>
int main()
{
int nodes, moves = 0;
std::cin >> nodes;
for (int index = 0; index < nodes; index++)
{
link_one.add(1);
}
link_one.print();
}
I have been trying to figure out how to read in user input without having to manually type every example out. I am building a stone game that is supposed to familiarize me with circularly linked lists. I have to manually type out examples like this to achieve the output. Is there another approach to replace this, and read example texts?**
Here is the code I want to include the implementation in:
#include <iostream>
int main()
{
int nodes, moves = 0;
std::cin >> nodes;
for (int index = 0; index < nodes; index++)
{
link_one.add(1);
}
link_one.print();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于令人讨厌的长输入,一个有用的解决方法是暂时使用带有
std::getline
函数的文本文件。只需将#include
替换为#include
即可,直到程序完成。你可以在这个答案中找到一个很好的解释这个答案。
编辑:您还需要将 iostream 声明更改为 fstream 声明
A useful workaround to obnoxiously long inputs is temporarily using a text file with the
std::getline
function. Just replace#include <iostream>
with#include <fstream>
until the program is done.you can find a pretty good explanation of that in this SO answer.
Edit: you'll also need to change your iostream declaration to an fstream one