macOS Clang C++17 filesystem header not found

前端 未结 8 662
借酒劲吻你
借酒劲吻你 2020-12-14 06:30

I need to write a program using the (experimental) C++17 filesystem library but clang on my Mac (macOS 10.12.03) doesn\'t seem to

8条回答
  •  被撕碎了的回忆
    2020-12-14 06:55

    Recursive directory walk using ftw in c, more details here.

    On, -std=c++17 for macOS version 10.xx, filesystem header is not available.

    #include 
    #include 
    #include 
    #include 
    
     
    int list(const char *name, const struct stat *status, int type)
    {
         if (type == FTW_NS)
         {
             return 0;
         }
    
         if (type == FTW_F)
         {
             printf("0%3o\t%s\n", status->st_mode&0777, name);
         }
    
         if (type == FTW_D && strcmp(".", name) != 0)
         {
             printf("0%3o\t%s/\n", status->st_mode&0777, name);
         }
         return 0;
    }
    
    int main(int argc, char *argv[])
    {
         if(argc == 1)
         {
             ftw(".", list, 1);
         }
         else
         {
             ftw(argv[1], list, 1);
         }
    
         return 0;
    }
    

    output looks like following:

    0755    ./Shivaji/
    0644    ./Shivaji/20200516_204454.png
    0644    ./Shivaji/20200527_160408.png
    0644    ./Shivaji/20200527_160352.png
    0644    ./Shivaji/20200520_174754.png
    0644    ./Shivaji/20200520_180103.png
    0755    ./Saif/
    0644    ./Saif/Snapchat-1751229005.jpg
    0644    ./Saif/Snapchat-1356123194.jpg
    0644    ./Saif/Snapchat-613911286.jpg
    0644    ./Saif/Snapchat-107742096.jpg
    0755    ./Milind/
    0644    ./Milind/IMG_1828.JPG
    0644    ./Milind/IMG_1839.JPG
    0644    ./Milind/IMG_1825.JPG
    0644    ./Milind/IMG_1831.JPG
    0644    ./Milind/IMG_1840.JPG
    

提交回复
热议问题