Scene:
1. You already know that a library supports only a few image formats, Png,jpg,gif,bmp,tif,jpeg. Now when you load the file, you should determine if the file suffix name is the above supported format.
2. In general, it is not in the list that is supported, but it is necessary to iterate over multiple judgments.
Solution:
1. Find out through find by constructing a specific string structure. --- if there is a faster trouble to tell me, did not refer to the implementation of open source code, estimates should have.
"; jpg;png;bmp;jpeg;gif;"
Main.cpp
#include <iostream> #include <algorithm> #include <string.h> #include <assert.h>std::string Getfileposfix (const char* path) {char* pos = strrchr (Path, '. '); if (POS) {std::string str (pos+1);//1. Convert to lowercase//http://blog.csdn.net/infoworld/article/details/29872869std::transform (Str.begin (), Str.end (), Str.begin (),:: ToLower); return str;} return std::string ();} BOOL Issupportpos (const std::string& posfix,const std::string& support) {std::string str (";"); Str.append (Posfix). Append (";"); if (Support.find (str)!=std::string::npos) {return true;} return false;} int main (int argc, char const *argv[]) {Const char* posfix = "; jpg;png;bmp;jpeg;gif;"; Const char* Path = "E:\\picture\\11.ggif"; std::string posfix = Getfileposfix (path); std::cout << Posfix << std :: Endl;assert (! Issupportpos (posfix,posfix));p ath = "E:\\picture\\11.gif";p osfix = getfileposfix (path); Std::cout << Posfix < < Std::endl;assert (Issupportpos (Posfix,posfix)); return 0;}
[c/c++]_[determines if the file name suffix is the fastest format supported]