I have
const char *pathname = "..somepathsomemorepathsomefile.ext";
how to transform that into
"..somepathsomemorepath"
?
See Question&Answers more detail:osI have
const char *pathname = "..somepathsomemorepathsomefile.ext";
how to transform that into
"..somepathsomemorepath"
?
See Question&Answers more detail:osThe easiest way is to use find_last_of
member function of std::string
string s1("../somepath/somemorepath/somefile.ext");
string s2("..\somepath\somemorepath\somefile.ext");
cout << s1.substr(0, s1.find_last_of("\/")) << endl;
cout << s2.substr(0, s2.find_last_of("\/")) << endl;
This solution works with both forward and back slashes.