问题描述
此函数返回一个字符串数组,其中包含文件夹中的文件列表。看起来像这样:
"folder//xyz.txt"
如何使它看起来像这样?
folder//xyz.txt
相同,但没有""
。
vector<string> list_of_files(string folder_name)
{
vector<string> files;
string path = folder_name;
for (const auto& entry : fs::directory_iterator(path))
{
stringstream ss;
ss << entry.path(); //convert entry.path() to string
string str = ss.str();
files.push_back(ss.str());
}
return files;
}
解决方法
删除字符串的第一个和最后一个字符很容易:
bpo_interface.o
您的引号来自插入流(quoted
is used to help prevent bugs due to spaces down the line)的路径。
幸运的是,您不需要任何这些:正如注释中所述,完全不需要字符串流;如果您要求,路径已经转换为字符串:
T = std::string