title: Why string comparison results an infinite loop
body: <p>I have a Plane's entity class such as:</p>
  
  <pre><code>class Plane{
  private:
      string tailNumber;
  public:
      void setTail(string tail);
      string getTail();
  }
  </code></pre>
  
  <p>and a Planes' collection class such as:</p>
  
  <pre><code>class Planes{
  public:
      void addPlane();
      void printDetails();
      void printAllPlanes();
  private:
      vector&lt;Plane&gt; currentPlane;
  }
  </code></pre>
  
  <p>addPlane definition:</p>
  
  <pre><code>void Planes::addPlane(){
      Plane a;
      string temp;
      cout &lt;&lt; "Enter tail:";
      getline(cin, temp);
      a.setTail(temp);
      currentPlane.push_back(a);
  }
  </code></pre>
  
  <p>My printDetails definition:</p>
  
  <pre><code>void Planes::printDetails()
  {
  cout &lt;&lt; "Enter Plane's Tail Number: ";
          getline(cin, tail);
          cin.ignore();
  
          for (unsigned int i = 0; i &lt; currentPlane.size(); i++)
          {
              if (currentPlane[i].getTailNumber() == tail)
              {
  //print tail number by calling accessor function}
  }
  else
  {
  cout &lt;&lt; "Error.";
  }
  }
  </code></pre>
  
  <p>and my main class:</p>
  
  <pre><code>int main(){
      Plane a;
      int userChoice;
      do{
          cout &lt;&lt; "1.Add Plane";
          cout &lt;&lt; "2.Print All Planes";
          cout &lt;&lt; "3.Print a plane";
          cout &lt;&lt; "4.Quit";
          cin &gt;&gt; userChoice;
          if (userChoice == 1)
              a.addPlane();
          else if (userChoice == 2)
              a.printAllPlanes();
          else if (userChoice == 3)
              a.printDetails();
      }while (userChoice != 4);
      return 0;
  }
  </code></pre>
  
  <p>I am successfully adding a new object and print all objects in my vector to display. The problem is if my tail number is: "TGA", then running currentPlane[0].getTail() return "TGA". However, when compare the user-input variable tail = "TGA" with currentPlane[0].getTail() = "TGA" yields an infinite-loop of do-while menu for some reason that I do not understand (because it is a simple string comparison?).</p>
  
  <p>If I only enter integer value such as "12345", then it will jump to the else branch instead of infinite-looping. If I enter any alphanumeric value, then the infinite-looping will appear again.
  Can you help me, please?</p>