title: std::string compare( ) giving segmentation fault:
body: <p>So I am making a function that will add a new string to a vector of strings ONLY IF the string is a unique string not already contained in the vector. Here is my code:</p>
  
  <pre><code>void CityMapper::addToVector(string&amp; s)
  {
      bool newWord = true;
      if(numAirports &gt; 0)
      {
          for(int i = 0; i &lt; numAirports; i++)
          {
              if(airportNames[i].compare(s) == 0)
                  newWord = false;
          }
      }
      if(newWord == true)
      {
          airportNames.pushBack(s);
          numAirports++;
      }
  }
  </code></pre>
  
  <p>airportNames is the vector of strings. When I run the program, it segfaults with the following errors in Valgrind:</p>
  
  <pre><code>Process Terminating with default action of signal 11 (SIGSEGV)
  Access not within mapped region at address 0x0
  </code></pre>
  
  <p>Before this happens, This error appears in the Valgrind terminal:</p>
  
  <pre><code>Invalid Read of Size 8
  </code></pre>
  
  <p>Both are happening at the string.compare() line. Does anyone know why this would be happening? I also tried the function without the &amp; symbol in the parameters.</p>
  
  <p><strong>EDIT:</strong> I took Derek's advice and made all of his changes. Now the program is segfaulting at a different method where I read in the strings from a file. Here is the code for that function:</p>
  
  <pre><code>void CityMapper::getCities()
  {
      ifstream fin;
      fin.open(flightDataFile);
      fin &gt;&gt; numAirports;
      string tempCity1, tempCity2, tossout;
      while(getline(fin, tempCity1, ','))
      {
          fin.ignore(1);
          getline(fin, tempCity2, ',');
          fin.ignore(1);
          getline(fin, tossout, '\n');
          addToVector(tempCity1);
          addToVector(tempCity2);
      }
  }
  </code></pre>
  
  <p>Here are the error messages from Valgrind:</p>
  
  <pre><code>==8357== Use of uninitialised value of size 8
  ==8357==    at 0x4EF158B: std::basic_string&lt;char, std::char_traits&lt;char&gt;,     
  std::allocator&lt;char&gt; &gt;::basic_string(std::string const&amp;) (in /usr/lib/x86_64-linux-
  gnu/libstdc++.so.6.0.17)
  ==8357==    by 0x402214: CityMapper::getCities() (in 
  /home/charlie/NetBeansProjects/Lab4/Lab4)
  ==8357==    by 0x401EB7: CityMapper::run() (in /home/charlie/NetBeansProjects/Lab4/Lab4)
  ==8357==    by 0x4050A0: main (in /home/charlie/NetBeansProjects/Lab4/Lab4)
  ==8357== 
  ==8357== Invalid read of size 4
  ==8357==    at 0x4EF158B: std::basic_string&lt;char, std::char_traits&lt;char&gt;, 
  std::allocator&lt;char&gt; &gt;::basic_string(std::string const&amp;) (in /usr/lib/x86_64-linux-
  gnu/libstdc++.so.6.0.17)
  ==8357==    by 0x402214: CityMapper::getCities() (in   
  /home/charlie/NetBeansProjects/Lab4/Lab4)
  ==8357==    by 0x401EB7: CityMapper::run() (in /home/charlie/NetBeansProjects/Lab4/Lab4)
  ==8357==    by 0x4050A0: main (in /home/charlie/NetBeansProjects/Lab4/Lab4)
  ==8357==  Address 0xfffffffffffffff8 is not stack'd, malloc'd or (recently) free'd
  ==8357== 
  ==8357== 
  ==8357== Process terminating with default action of signal 11 (SIGSEGV)
  ==8357==  Access not within mapped region at address 0xFFFFFFFFFFFFFFF8
  ==8357==    at 0x4EF158B: std::basic_string&lt;char, std::char_traits&lt;char&gt;, 
  std::allocator&lt;char&gt; &gt;::basic_string(std::string const&amp;) (in /usr/lib/x86_64-linux-
  gnu/libstdc++.so.6.0.17)
  ==8357==    by 0x402214: CityMapper::getCities() (in 
  /home/charlie/NetBeansProjects/Lab4/Lab4)
  ==8357==    by 0x401EB7: CityMapper::run() (in /home/charlie/NetBeansProjects/Lab4/Lab4)
  ==8357==    by 0x4050A0: main (in /home/charlie/NetBeansProjects/Lab4/Lab4)
  </code></pre>