title: How to check if string ends with .txt
body: <p>I am learning basic C++, and right now I have gotten a string from a user and I want to check if they typed the entire file name (including .txt) or not. I have the string, but how can I check if the string ends with ".txt" ?</p>
  
  <pre><code>string fileName;
  
  cout &lt;&lt; "Enter filename: \n";
  cin &gt;&gt; fileName;
  
  string txt = fileName.Right(4);
  </code></pre>
  
  <p>The <code>Right(int)</code> method only works with CString, so the above code does not work. I want to use a regular string, if possible. Any ideas?</p>