c++ 循环遍历删除某类文件

2020-02-27  本文已影响0人  送分童子笑嘻嘻

//删除原来new文件

#include<iostream>
#include<cstdio>
#include <string.h>
#include <unistd.h>
using namespace std;
//cmakelist中要添加c++11  set(CMAKE_CXX_STANDARD 11)
int main(){
    int count = 1;
    while (1) {
        string filepath = "/home/cai/mrpt/mrpt15/mrpt/apps/GridmapNavSimul/new" + to_string(count)+".pgm";
        char filename_buf[filepath.size()];
        strcpy(filename_buf, filepath.c_str());
        if (access(filename_buf, 0) == -1) {
            std::cout << "no file to remove" << std::endl;
            break;
        }
        remove(filename_buf);
        count++;
    }
return 0;
}
上一篇下一篇

猜你喜欢

热点阅读