如何在不手动输入的情况下适当阅读用户输入?

发布于 2025-01-18 08:05:26 字数 332 浏览 3 评论 0原文

我一直在尝试弄清楚如何在用户输入中阅读,而不必手动输入每个示例。我正在建造一款石头游戏,应该使我熟悉循环链接的列表。我必须手动输入这样的示例才能实现输出。是否有另一种替换的方法,并阅读示例文本

#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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

爱她像谁 2025-01-25 08:05:26

对于令人讨厌的长输入,一个有用的解决方法是暂时使用带有 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文