How to get file extension from string in C++

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

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

I need a cross platform solution.

25条回答
  •  清歌不尽
    2020-11-30 23:32

    I used PathFindExtension() function to know whether it is a valid tif file or not.

    #include 
    bool A2iAWrapperUtility::isValidImageFile(string imageFile)
    {
        char * pStrExtension = ::PathFindExtension(imageFile.c_str());
    
        if (pStrExtension != NULL && strcmp(pStrExtension, ".tif") == 0)
        {
            return true;
        }
    
        return false;
    }
    

提交回复
热议问题