title: C++ Find string before text
body: <p>The given code gets all the text <strong>after</strong> a specific point in a string and works very well. </p>
  
  <pre><code>if(text.find("what ") != std::string::npos)
          {
              foundtext = text.substr(text.find("what ") + 5);
              cout &lt;&lt; foundtext &lt;&lt; endl;
          }
  </code></pre>
  
  <p>The next problem that I can't figure out even after searching, is to find the material <strong>before</strong> a specific point. Unfortunetely it wasn't as simple as turning the +5 into a -5. How could I fint the string that comes before "what "?</p>