#include <iostream>
#include <string>
using namespace std;
int main() {
string filename = "test1.JPG";
if (filename .substr(filename .find_last_of(".") + 1) == "JPG") {
cout << "是.JPG文件" << std::endl;
filename = filename .substr(0, filename .length() - 4);
cout << filename << endl;
} else {
std::cout << "不是.JPG文件" << std::endl;
}
}
应输出test1。