You should use std::string_view to pass a parameter to a function (or return a value from a function), instead of std::string const & unless your code needs to call other functions that take std::string parameters (in which case, conversions would be necessary):
std::string_view get_filename(std::string_view str)
{
auto const pos1 {str.find_last_of('')};
auto const pos2 {str.find_last_of('.')};
return str.substr(pos1 + 1, pos2 - pos1 - 1);
}
char const file1[] {R"(c: estexample1.doc)"};
auto name1 = get_filename(file1);
std::string file2 {R"(c: estexample2)"};
auto name2 = get_filename(file2);
auto name3 = get_filename(std::string_view{file1, 16});