更新时间:2023-02-23 20:10:40
最简单的方法是使用 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.