【发布时间】:2021-08-29 18:57:29
【问题描述】:
我有一个directory_iterator,我想要文件名,但我似乎无法正常工作,它只是抛出一个错误,指出value_type* 无法转换为string。
我无法将其转换为字符串,std::to_string() 也不起作用!
for (auto& p : std::experimental::filesystem::directory_iterator(dir)) {
auto path = p.path().filename().c_str();
//this doesn't work
std::ifstream comp("Json/" + path, std::ifstream::binary);
//neither does this
char f[50] = "Json/";
std::strcpy(f, path);
std::ifstream comp(f, std::ifstream::binary);
}
【问题讨论】:
-
您不能将 C 字符串与
operator+连接。 -
“不起作用” - 是一个糟糕的问题描述。您应该准确地描述问题。
-
请澄清您的具体问题或提供其他详细信息以准确突出您的需求。正如目前所写的那样,很难准确地说出你在问什么。