【发布时间】:2017-10-04 14:45:39
【问题描述】:
我有很多未缩进的 C/C++ 源文件。我想以编程方式美化它们。我怎样才能做到这一点?
【问题讨论】:
-
您使用的是哪个 IDE? Google 是您的朋友。
我有很多未缩进的 C/C++ 源文件。我想以编程方式美化它们。我怎样才能做到这一点?
【问题讨论】:
编写一个python脚本,调用像Artistic Style这样的C++美化器。
http://astyle.sourceforge.net/
这是您的 Python 脚本的外观:
# Collect all the files you need to beautify in "files"
#Loop through each C/C++ file
for file in files:
command = "astyle " + file
import subprocess
process = subprocess.Popen(command.split(), stdout=subprocess.PIPE)
output, error = process.communicate()
艺术风格的示例用法是:
astyle example.cpp
或
astyle --style=ansi --indent=tab example.cpp
【讨论】: