MFC C++中从字符串中分离文件名和路径

解析字符串路径方法如下:

文件名的获取:

CString fileName;
int iName=fileName.GetLength()-fileName.ReverseFind('\\')-1;
fileName=fileName.Right(iName);

结果如下所示
MFC C++中从字符串中分离文件名和路径_第1张图片

获取文件路径:

CString filePath;
int iPath=fileName.ReverseFind('\\')+1;
filePath = fileName.Left(iPath);

结果如下所示:
MFC C++中从字符串中分离文件名和路径_第2张图片

获取文件后缀名:

CString fileType;
int iType=m_RichFileName.GetLength()-m_RichFileName.ReverseFind('.')-1;
fileType= m_RichFileName.Right(iType);

结果如下所示:
MFC C++中从字符串中分离文件名和路径_第3张图片

你可能感兴趣的:(c++,mfc,microsoft,cstring)