Go back to Richel Bilderbeek's homepage.

Go back to Richel Bilderbeek's C++ page.

 

 

 

(C++) RemovePath

 

std::string code snippet to r emove a filename's path.

 

*        View the code of 'RemovePath' in plain text

 

 

 

#include <string>

#include <cassert>

 

//From http://www.richelbilderbeek.nl/CppRemovePath.htm

//Returns the filename without path

const std::string RemovePath(const std::string& filename)

{

const int sz = static_cast<int>(filename.size());

const int path_sz = filename.rfind("\\",filename.size());

if (path_sz == sz) return filename;

return filename.substr(path_sz + 1,sz - 1 - path_sz);

}

 

 

 

 

Go back to Richel Bilderbeek's C++ page.

Go back to Richel Bilderbeek's homepage.