以下是一个使用C++判断LPCTSTR文本后缀是否为.svg的代码示例:

#include <iostream>
#include <string>

bool IsSVGFile(LPCTSTR filePath)
{
    std::string strFilePath(filePath);

    // 查找最后一个点的位置
    size_t dotPos = strFilePath.find_last_of(".");
    if (dotPos == std::string::npos) {
        return false; // 没有找到点,说明没有后缀
    }

    // 获取后缀名
    std::string fileExtension = strFilePath.substr(dotPos + 1);
    
    // 比较后缀名是否为.svg
    return (fileExtension == "svg");
}

int main()
{
    LPCTSTR filePath = "example.svg";
    bool isSVG = IsSVGFile(filePath);
    if (isSVG) {
        std::cout << "文件后缀为.svg" << std::endl;
    } else {
        std::cout << "文件后缀不是.svg" << std::endl;
    }
    
    return 0;
}

在上述代码中,我们首先将LPCTSTR转换为std::string类型的filePath。然后通过查找最后一个点的位置,找到文件名中的后缀名。最后,将后缀名与".svg"进行比较,如果相等,则返回true,否则返回false

c++判断LPCTSTR文本后缀是否为svg的代码

原文地址: http://www.cveoy.top/t/topic/iDht 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录