How to get file extension from string in C++

前端 未结 25 2501
迷失自我
迷失自我 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:20

    Or you can use this:

        char *ExtractFileExt(char *FileName)
        {
            std::string s = FileName;
            int Len = s.length();
            while(TRUE)
            {
                if(FileName[Len] != '.')
                    Len--;
                else
                {
                    char *Ext = new char[s.length()-Len+1];
                    for(int a=0; a

    This code is cross-platform

提交回复
热议问题