title: Compare variable with each line from a txt file
body: <p>I have to compare each line of a txt file with a user input variable.
  If the userinput word exists within the txt file, it should prompt the user "The word exists." and if it does not, than exit the program.</p>
  
  <p>This is what the text file looks like:</p>
  
  <pre><code>hello
  hey
  wow
  your
  </code></pre>
  
  <p>Here is my code:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;fstream&gt;
  #include &lt;string&gt;
  using namespace std;
  
  int main() {
  
      ifstream file("words.txt");
      string content;
      string userinput;
  
      while(file &gt;&gt; content) {
          cout &lt;&lt; content &lt;&lt; endl; // gets all the lines from the txt file
  
          while(userinput != "exit") {
              // asks user for input
              cin &gt;&gt; userinput;
  
              // compares two inputs 
              if (userinput == content)
              {
                  cout &lt;&lt; "The word exists." &lt;&lt; endl;
              } else {
                  break;
              }
  
              if (userinput == "exit") {
                  break;
              }
          }
      }
      return 0;
  }
  </code></pre>
  
  <p>Its not working for me. I am able to return all the words from the txt file but not able to compare the userinput text with the txt lines from the txt file. Any help would be great. Thanks!</p>
  
  <p>Updated code:</p>
  
  <pre><code>    while(iFile &gt;&gt; content) {
          while(userinput != "exit") {
              // asks user for input
              cin &gt;&gt; userinput;
  
              // compares two inputs 
              if (content.find(userinput) != std::string::npos)
              {
                  cout &lt;&lt; "The word exists." &lt;&lt; endl;
              } else {
                  break;
              }
  
              if (userinput == "exit") {
                  break;
              }
          }
      }
  </code></pre>
  
  <p>P.S: I am pretty new to c++. A student</p>