Note that there are some explanatory texts on larger screens.

plurals
  1. POconfusion about lists and pairs
    primarykey
    data
    text
    <p>So I'm experimenting with trying to add first and last names into a double linked list. I have a various text files of different lengths with the format "string, string", and am using list> to store my data.</p> <p>I am using this code:</p> <pre><code>typedef std::list&lt; std::pair&lt;string,string&gt; &gt; listPair; </code></pre> <p>...</p> <pre><code>list&lt;pair&lt;string, string&gt; &gt; mylist; ifstream myFile; myFile.open("20.txt"); pair&lt;string, string&gt; stuff; while (myFile &gt;&gt; stuff.first &gt;&gt; stuff.second) { mylist.push_back(stuff); } listPair::iterator iter = mylist.begin(); for(;iter != mylist.end();iter++) { string s = (*iter).first; cout &lt;&lt; s &lt;&lt; endl; string c = (*iter).second; cout &lt;&lt; c &lt;&lt; endl; } </code></pre> <p>now the problem i'm having is that firstly, the last item in the list is not being added. like every file just misses the end line, so that's a little confusing.</p> <p>also, I'm doing a "mylist.size()" to ensure all the names have been added, and it's confusing me because say for a text file containing 99 names, i.e 99 lines of text, it will say (not forgetting it only reads in 98 due to missing the last line) that the list has size 48. </p> <p>WHY 48? Is it something to do because I have done pairs, which still would not make sense as if it was not reading in pairs there would actually be double the about, since the pairs are just to take the first and last name as one value.</p> <p>Mind boggling to me.</p> <p>once again thanks for all your help!</p>
    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.
 

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