C++11 variant (inspired by James Kanze's version) with uniform initialization and anonymous inline lambda.
std::string basename(const std::string& pathname)
{
return {std::find_if(pathname.rbegin(), pathname.rend(),
[](char c) { return c == '/'; }).base(),
pathname.end()};
}
It does not remove the file extension though.