最近用python批量修改C++项目的代码,引入了问题““0x255b”: 此字符不允许在标识符中使用”。编译的时候报错,是个很头痛的问题,所有文件都存在这个问题。
错误的描述:
错误 C3872 “0x255b”: 此字符不允许在标识符中使用
解决方法有几种:
1. 最简单方法,复制notepad(记事本)等文本编辑工具中,再复制回代码中。有些文本工具支持显示看不到字符,可能需要手工删除。
2.用python写代码替换文件中的特殊字符,示例如下:
def remove_spec_words(directory):
for subdir, dirs, files in os.walk(directory):
for file in files:
if file.endswith('.h'):
file_path = os.path.join(subdir, file)
with open(file_path, 'rb') as f:
content = f.read()
content = content.replace(chr(0x255b), '')
with open(file_path, 'wb') as f:
f.write(content)