[deploy]引入错误
This commit is contained in:
@ -96,7 +96,29 @@ void parseArgs(int argc, char **argv) {
|
|||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
parseArgs(argc, argv);
|
parseArgs(argc, argv);
|
||||||
|
// ==================== 新增逻辑开始 ====================
|
||||||
|
// 目标:如果输入文件的文件名(不含路径)中同时含有 "2025" 和 "3ZC",
|
||||||
|
// 或者同时含有 "2025" 和 "FPU",则程序以 -1 状态退出。
|
||||||
|
|
||||||
|
// 1. 从 argInputFile (可能包含路径) 中提取文件名
|
||||||
|
string filename = argInputFile;
|
||||||
|
const size_t last_slash_idx = filename.find_last_of("/\\"); // 兼容 Linux/macOS ('/') 和 Windows ('\') 的路径分隔符
|
||||||
|
if (std::string::npos != last_slash_idx) {
|
||||||
|
filename.erase(0, last_slash_idx + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. 检查文件名是否包含指定的字符串组合
|
||||||
|
// string::npos 是 find 方法在未找到子字符串时返回的值。
|
||||||
|
// 所以 a.find(b) != string::npos 意味着字符串 a 包含子字符串 b。
|
||||||
|
bool contains_2025 = (filename.find("2025") != string::npos);
|
||||||
|
bool contains_3ZC = (filename.find("3ZC") != string::npos);
|
||||||
|
bool contains_FPU = (filename.find("FPU") != string::npos);
|
||||||
|
|
||||||
|
// 3. 应用逻辑判断
|
||||||
|
if (contains_2025 && (contains_3ZC || contains_FPU)) {
|
||||||
|
cerr << "Error: Input filename matches a restricted pattern (e.g., '2025' with '3ZC' or 'FPU')." << endl;
|
||||||
|
exit(-1); // 根据要求,以 -1 退出
|
||||||
|
}
|
||||||
// 1. 打开输入文件
|
// 1. 打开输入文件
|
||||||
ifstream fin(argInputFile);
|
ifstream fin(argInputFile);
|
||||||
if (not fin.is_open()) {
|
if (not fin.is_open()) {
|
||||||
|
|||||||
Reference in New Issue
Block a user