如果oldname为一个文件而不是目录,那么为该文件更名。 cout << "fail" << endl; } else { string path3 = "C:\\Users\\Zender\\Desktop\\object\\" + to_string(i) + "\\cam_" + to_string(j) + ".png"; string path4 = "C:\\Users\\Zender\\Desktop\\object\\cam_" + to_string(j) + "\\" + to_string(i) + ".png"; cout << path3 << endl; if (rename(path3.c_str(), path4.c_str()) != 0) cout << "fail" << endl; } } } return 0; }