title: string compare failing after reading line from txt file
body: <p>I am trying to read a file line by line and compare it to string in the code. But somehow the following code is not giving expected result. I do not follow what am I missing during the comparison:</p>
  
  <p><strong>CODE</strong></p>
  
  <pre><code>int main(int argc, char** argv)
  {
      std::string filePath="E:\\data\\stopfile.txt";
      std::string line;
      std::ifstream myfile;
      std::string test="ball";
      myfile.open(filePath.c_str());
      if(myfile.is_open()){
          while(getline(myfile,line)){
              std::cout&lt;&lt;line&lt;&lt;std::endl;
              if(!line.compare(test)){
                  std::cout&lt;&lt;"SUCCESS"&lt;&lt;std::endl;
              }
              else{
                  std::cout&lt;&lt;"FAIL"&lt;&lt;std::endl;
              }
          }
      }
      myfile.close();
  
      if(!test.compare("ball")){
          std::cout&lt;&lt;"SUCCESS"&lt;&lt;std::endl;
      }
  }
  </code></pre>
  
  <p><strong>OUTPUT</strong></p>
  
  <pre><code>apple
  FAIL
  ball
  FAIL
  cat
  FAIL
  SUCCESS
  </code></pre>
  
  <p>I expect the program to print SUCCESS after the line of "ball". But the comparison does not seem to be success. </p>
  
  <p>I have also tried the comparison condition to </p>
  
  <pre><code>if(!line.compare(test.c_str())){
  </code></pre>
  
  <p>Still the result is the same.</p>