title: Is there a more efficient way to extract the file name of a file?
body: <p>The code bellow extracts the file name of a file using its path.</p>
  <pre><code>#include &lt;iostream&gt;
  #include &lt;vector&gt;
  
  using namespace std;
  
  int main() {
      cout &lt;&lt; &quot;Program operating...&quot; &lt;&lt; endl;
  
      string s = &quot;C:\\Users\\user\\Pictures\\Strategic_Offense_Logo_1&quot;;
      string name;
      for (unsigned int i = s.size() - 1; i &gt; 0; i--) {
          if (s[i] == '\\') {
              for (unsigned int j = i + 1; j &lt; s.size(); j++) {
                  if (s[j] == '.' || j == s.size() - 1) {
                      if (j == s.size() - 1)
                          j++;
                      vector&lt;char&gt; v(j - i - 1);
                      unsigned int l = 0;
                      for (unsigned int k = i + 1; k &lt; j; k++) {
                          v[l++] = s[k];
                      }
                      char* vectorAsArray = &amp;v[0];
                      name = vectorAsArray;
                      name.resize(v.size());
                      break;
                  }
              }
              break;
          }
      }
      cout &lt;&lt; name &lt;&lt; endl;
  }
  </code></pre>
  <pre><code>#include &lt;iostream&gt;
  #include &lt;vector&gt;
  
  using namespace std;
  
  int main() {
      cout &lt;&lt; &quot;Program operating...&quot; &lt;&lt; endl;
  
      string s = &quot;C:\\Users\\user\\Pictures\\Strategic_Offense_Logo_1.png&quot;;
      string name;
      for (unsigned int i = s.size() - 1; i &gt; 0; i--) {
          if (s[i] == '\\') {
              for (unsigned int j = i + 1; j &lt; s.size(); j++) {
                  if (s[j] == '.' || j == s.size() - 1) {
                      if (j == s.size() - 1)
                          j++;
                      vector&lt;char&gt; v(j - i - 1);
                      unsigned int l = 0;
                      for (unsigned int k = i + 1; k &lt; j; k++) {
                          v[l++] = s[k];
                      }
                      char* vectorAsArray = &amp;v[0];
                      name = vectorAsArray;
                      name.resize(v.size());
                      break;
                  }
              }
              break;
          }
      }
      cout &lt;&lt; name &lt;&lt; endl;
  }
  </code></pre>
  <p>Is there a more efficient way to do this?</p>
  <p>Purpose:
  I am making a texture class and I want to refer the texture by its name instead of its path or a made up ID.</p>
  <p>Note:  library does not work at all with the visual studio compiler. If you know how to fix it or have an alternative solution, please post.
  <a href="https://i.stack.imgur.com/X3YJz.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/X3YJz.png" alt="enter image description here" /></a></p>