(C++) RemovePath
January 7, 2018 · View on GitHub
(C++) RemovePath
RemovePath is a std::string and file I/O code snippet to remove a filename's path.
#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); }