Note that there are some explanatory texts on larger screens.

plurals
  1. POInitializing nodes in a list from a .txt file
    primarykey
    data
    text
    <p>Currently have a custom Linked List class that works well.</p> <p>I implemented a function that can export all the contents of each Node to a .txt file when the program exits. I now want to import that same file to re-populate the list at the program start, and that's where I ran into some difficulty. (the <code>&gt;&gt;</code> and <code>&lt;&lt;</code> operators are overloaded) and this entire linked-list class is specific to this program and not really meant to be re-usable. </p> <p>my export function:</p> <pre><code>void List::exportData(){ Node *currentPtr = Head; cout&lt;&lt;"Saving Data..."&lt;&lt;endl; ofstream fileOut("stock_transaction_history.txt"); while (currentPtr != 0){ fileOut&lt;&lt; currentPtr-&gt;symbol &lt;&lt; " " &lt;&lt;currentPtr-&gt;shares&lt;&lt;endl; currentPtr = currentPtr-&gt;next; //iterates down the list } } </code></pre> <p>Now I'm completely stuck on the import data feature. I also have a function <code>addToBack((Node *newPtr)</code> at my disposal if necessary.</p> <pre><code>void List::importData(){ Node *currentPtr ifstream stockIn("stock_transaction_history.txt"); } stockIn &gt;&gt; currentPtr-&gt;symbol &gt;&gt;currentPtr -&gt;shares;//(Node(tempSymbol, num)); currentPtr = currentPtr-&gt;next; stockIn.close(); </code></pre> <p>}</p> <p>I'm thinking I might have to call <code>addToBack</code> via something along the lines of <code>Node *tempPtr=new Node();</code> or just call the generic <code>data</code> portion of my node?</p> <p>here is my <code>node.h</code></p> <pre><code>class Node { private: friend class List; string symbol; int shares; Node *next; public: Node() : next(0) { } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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