enum IMAGEFORMAT { JPG, BMP} imageExt; int GetImageFormat(char *ext) { if(!stricmp(ext, "jpg")) imageExt = JPG; else if( !stricmp(ext, "bmp") ) imageExt = BMP; else cout<<"未知的图像格式!\n"; return imageExt; } int main() { char *ext = "bmp"; switch(GetImageFormat(ext)) { case JPG: cout<<"图像格式为JPG\n"; break; case BMP: cout<<"图像格式为BMP\n"; break; default: cout<<"没有符合的图像格式,退出!\n"; } return 0; }
原文:http://www.cnblogs.com/kingboys/p/3916781.html