title: Finding a number of a line with a specific string in a file
body: <p>I want my program to return number of line in which there is a specific string.
  Whole line should be this string.</p>
  
  <p>I don't know why it always returns a length of whole file.</p>
  
  <p>My code:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  #include &lt;fstream&gt;
  #include &lt;limits&gt;
  #include &lt;windows.h&gt;
  
  using namespace std;
  
  
  int main () {
  int x;
  x=0;
  string filename, inputfilename, line;
  ifstream inputfile;
  
  while(!inputfile.is_open()) {
      cout &lt;&lt; "Input filename: ";
      getline (cin, inputfilename);
      inputfile.open(inputfilename.c_str(),ios::in | ios::binary);
  }
  
  //string obj = "[I.LOVE.COOKIES]"; //Was like this
  string obj = "[I.LOVE.COOKIES]\r"; //Adding \r solved the problem
  while(getline(inputfile, line))
  {
      if(line==obj)
      {
          return x;
      }
      else
      {
          x++;
      }
  
  }
  return 0;
  }
  </code></pre>