我有以下代码。
它的作用是从相对路径中删除文件名。
我预期的结果是“.\png”,但我得到的是一个空字符串...
#include <iostream>
#include <filesystem>
#include <string>
//using namespace std;
namespace fs = std::filesystem;
#define VNAME(xx) (#xx)
int main() {
std::cout << "Hello World!" << "\n";
std::string fpath = ".\\png\\DUMMY-AB-42-L.PNG";
auto fs_fpath = fs::path(fpath);
auto fs_fpath_str = fs_fpath.string();
std::cout << VNAME(fpath) << ":=" << fpath << "\n";
std::cout << VNAME(fs_fpath_str) << ":=" << fs_fpath_str << "\n";
fs_fpath.remove_filename();
fs_fpath_str = fs_fpath.string();
std::cout << VNAME(fs_fpath_str) << ":=" << fs_fpath_str << "\n";
return 0;
}
输出为:
Hello World!
fpath:=.\png\DUMMY-AB-42-L.PNG
fs_fpath_str:=.\png\DUMMY-AB-42-L.PNG
fs_fpath_str:=
简单的问题是:错误还是功能?