Note that there are some explanatory texts on larger screens.

plurals
  1. POC++: How do I "store" nodes
    text
    copied!<p>So I am trying to read data in the following format from a text file for a simple maze game:</p> <pre> A * B * * B * C * A C G D * B D * * * C E I F * * F J G * E G * H C F H * * * G I * * E * J * K F * K * L * J L * * * K </pre> <p>The first column is the current node. The second column, the node to its immediate north. Third, to its immediate east, Fourth, to the immediate south, and fifth, to the immediate west. Any * represents no node, and the pointer should be set to null.</p> <p>Keeping in mind that I am a rookie at OOP, I am curious how to go about "saving" this information into a class called Node.</p> <p>I've got the following class definition:</p> <pre><code>public: int BuildGraph(); char name; char north; char east; char south; char west; }; std::vector&lt;Node&gt; nodes; </code></pre> <p>With the code <code>build &gt;&gt; node.name &gt;&gt; node.north &gt;&gt; node.east &gt;&gt; node.south &gt;&gt; node.west;</code> the correct characters are read in.</p> <p>This correctly gets the characters that I want. However, once I get to the end of the line, how do I store this node and then move on to the next line and store THAT node? Right now, I've got a do/while loop that loops through this until it reaches the end of file but of course it overwrites everything each time it goes through so the only code it is effectively reading in is the last line of L * * * K. How do I get the first line to save as node A, the second as node B, etc? How do I reference this elsewhere in the program? Right now, I'm just creating an object node of type Node. When I get to the end of the line, I need everything in node to be copied to a new Node, called A. </p> <p>EDIT: Sorry about the formatting; Stack Overflow is not recognizing my 4 spaces as indention of code.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload