title: Reading in one word from a file
body: <p>I'm new to C++, and I need to find the one word inputted (searchWord) within the text file &quot;input.txt&quot;.</p>
  <p>I have it now where it will output every word in the file, but I need it to just output the inputted string and find it.</p>
  <pre><code>#include&lt;iomanip&gt;
  #include&lt;fstream&gt;
  #include&lt;string&gt;
  using namespace std;
  
  int main(){
      // Variable Declaration
      string fileName;
      string searchWord;
      int exitValue = 0;
  
      // Name the file to open
      ifstream inputFile;
  
      // Prompt the user to enter the file name
      cout &lt;&lt; &quot;Enter the name of the file: &quot;;
      cin &gt;&gt; fileName;
  
      // Logic to determine if the file name equals &quot;input.txt&quot;
      if (fileName == &quot;input.txt&quot;){ // if user input = input.txt
          inputFile.open(&quot;input.txt&quot;); // opening input.txt
      }
      else{
          cout &lt;&lt; &quot;\nCould not open '&quot; &lt;&lt; fileName &lt;&lt; &quot;'.&quot; &lt;&lt; endl;
          exit(0);
      }
  
      // Prompt the user for a word to search for in the file
      cout &lt;&lt; &quot;Enter a value to search for: &quot;;
      cin &gt;&gt; searchWord;
  
      // Logic to determine if the inputted string is in the file or not
      while (inputFile &gt;&gt; searchWord){
          cout &lt;&lt; &quot;\n'&quot; &lt;&lt; searchWord &lt;&lt; &quot;' was found in '&quot; 
              &lt;&lt; fileName &lt;&lt; &quot;'.&quot; &lt;&lt; endl;
      }
  
      inputFile.close();
      return 0;
  }
  </code></pre>