从C 的文件中删除图像

Deleting images from a file with c++

本文关键字:删除 图像 文件      更新时间:2023-10-16

我想从文件中删除图像,图像命名为:" 1.jpg,2.jpg ....",我已经尝试了上面的代码,但它给了我这个错误:无匹配函数呼叫'remove(std :: __ cxx11 :: string&('

 int i;
 for (i=0;i<frame;i++)//frame contain the number of images i want to delete
 {
      std::stringstream ss;
     ss << i;
     std::string str = ss.str();
     const char *cstr = str.c_str();
     str=str+".jpg";
     remove(str);
 }

如果有人可以帮助您在建议方面。

您几乎拥有它。remove需要const char*,而不是std::string。这意味着您需要

remove(str.c_str());

我们也可以摆脱stringstream并在

之类的东西中使用std::to_string
for (i=0; i<frame; i++)
{
    const std::string str = to_string(i) + ".jpg";
    remove(str.c_str());
}