How to get file extension from string in C++

前端 未结 25 2520
迷失自我
迷失自我 2020-11-30 22:35

Given a string \"filename.conf\", how to I verify the extension part?

I need a cross platform solution.

25条回答
  •  旧时难觅i
    2020-11-30 23:20

    Actually, the easiest way is

    char* ext;
    ext = strrchr(filename,'.') 
    

    One thing to remember: if '.' doesn't exist in filename, ext will be NULL.

提交回复
热议问题