Skip to content

Instantly share code, notes, and snippets.

@bit-hack
Created February 11, 2020 23:29
Show Gist options
  • Save bit-hack/4e47029adffeeba112d61466cb0af353 to your computer and use it in GitHub Desktop.
Save bit-hack/4e47029adffeeba112d61466cb0af353 to your computer and use it in GitHub Desktop.
return the base of a given file path.
std::string base_path(std::string in) {
const size_t last1 = in.rfind('/');
const size_t last2 = in.rfind('\\');
const size_t last = std::max(last1 == std::string::npos ? 0 : last1,
last2 == std::string::npos ? 0 : last2);
in.resize(last);
return in;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment