场景: 图片格式判断和字符大小转换
用到函数
strrchr() 从字符的最后一个位置开始读起
strchr() 从字符的第一个位置开始读起
find() 查找字符串
#include <stdio.h>
#include <iostream>
#include <string>
#include <string.h>
#include <algorithm>
using namespace std;
std::string GetFilePosfix(const char* path)
{//获取文件后缀
std::string path_pos=strrchr(path,'.');
std::string path_format(path_pos,1);
std::cout<<"fun:"<<path_format<<endl;
transform(path_format.begin(),path_format.end(),path_format.begin(),::tolower);
return path_format;
}
bool IsSupported(const std::string currnet_format,const std::string supported_format)
{//判断后缀是否是支持的格式
std::string tmp_str(";");
tmp_str.append(currnet_format).a

本文介绍了三种获取文件后缀的方法:使用strrchr()函数从字符串末尾查找指定字符,使用strchr()函数从字符串开头查找,以及利用find()函数进行字符串查找。通过这些方法,可以轻松获取文件的扩展名。
订阅专栏 解锁全文
2171

被折叠的 条评论
为什么被折叠?



