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();
}
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