欢迎光临
我们一直在努力

【Clion】运行 'test.1.cpp' 时出错 找不到文件

问题详细

今天在Clion调试文件的时候一直提示:

运行 ‘test.1.cpp’ 时出错 找不到文件: C:\Users\24910\Desktop\code\c++\ACGO\test.1.exe

查看了目录下生成了test.1,但没有后缀名

查看构建日志:

g++.exe C:\Users\24910\Desktop\code\c++\ACGO\test.1.cpp -o test.1

所以是因为文件名中带 . 将后面的内容识别为了后缀名,从而导致没有生成exe

解决方法

将带 . 的文件改个名即可。

用于文件很多,我使用Python进行批量重命名:

import os

root_dir = '.'

for foldername, subfolders, filenames in os.walk(root_dir):
    for filename in filenames:
        if filename.endswith('.cpp'):
            name_only = filename[:-4]  # 去掉 .cpp
            if '.' in name_only:
                # 替换 . 为 空格
                new_name_only = name_only.replace('.', ' ')
                new_filename = new_name_only + '.cpp'
                old_path = os.path.join(foldername, filename)
                new_path = os.path.join(foldername, new_filename)
                # 重命名文件
                os.rename(old_path, new_path)
                print(f'Renamed: {old_path} → {new_path}')
赞(0) 打赏
未经允许不得转载:跑路博客 » 【Clion】运行 'test.1.cpp' 时出错 找不到文件