title: Copying unique string from one list to another list from text file
body: <p>I've been asked to make a list of data from a text file of words which is equal to a specific length of letters, the user inputs the length wanted and the function would make a list of all the words that have the same length. I tried making it with a list but changed to a vector but I still couldn't manage to make it work. I've been able to load all of the words in the text file into a vector (and also when it was a list) but only inserting the words of a given length caused issues and no words were entered into the vector. Would a map be better?</p>
  <pre class="lang-cpp prettyprint-override"><code>    vector&lt;string&gt; wordListA;
      vector&lt;string&gt; wordListB;
      int count = 0;
      myfile.open(filename); // opening the filename given in command line
      if (myfile.is_open()) //testing if the file is opened or not
      {
          while (getline(myfile, line))
          {
              string newline;
              newline = line;
              wordListA.push_back(newline);
          }
          vector&lt;string&gt;::const_iterator it;
          it = wordListA.begin();
          for (it; it != wordListA.end(); it++)
          {
              string c = *it;
              if (c.length() == wordLength + 1)
              {
                  wordListB.push_back(c);
                  count++;
              }
          }
          cout &lt;&lt; count &lt;&lt; endl;
  
      }
    else
      {
          cout &lt;&lt; &quot;Error when opening file: &quot; &lt;&lt; filename &lt;&lt; endl;
      }
    myfile.close();
  }
  </code></pre>
  <p>I think my method for finding the length is wrong. I tried 4 different methods and none worked! I do think I need to be using a list data structure and not a vector.
  previously I tried this which also didn't seem to work:</p>
  <pre class="lang-cpp prettyprint-override"><code>        string newline;
          newline= line; //load current line into nl
  
          if (int(newline.length()) == wordLength + 1)
          {
              wordListA.push_back(newline); //append into list
          } 
  </code></pre>
  <p>Updated but still doesnt work:</p>
  <pre><code>while (getline(myfile, line))
          {
              string newline;
              newline = line;
              if (int(newline.length()) == wordlength)
              {
                  wordListA.push_back(newline);
                  unique++;
              }
          }
  </code></pre>