借助 Clang 工具创建 C/C++ 代码格式化工具
在本教程中,我们将讨论一个借助 clang 工具创建 C/C++ 代码格式化工具的程序。
设置
sudo apt install python sudo apt install clang-format-3.5
然后,我们将创建一个 Python 文件,其位置为当前用户具有读写权限的位置。
示例
import os
cpp_extensions = (".cxx",".cpp",".c", ".hxx", ".hh", ".cc", ".hpp")
for root, dirs, files in os.walk(os.getcwd()):
for file in files:
if file.endswith(cpp_extensions):
os.system("clang-format-3.5 -i -style=file " + root + "/" + file)在当前用户的顶级目录中创建一个文件格式化文件。
输出
clang-format-3.5 -style=google -dump-config > .clang-format
最后,将此文件复制到当前项目的顶级目录中。
现在,你可以使用你自己的代码格式化工具了。只需运行创建的 Python,即可开始使用!
广告
数据结构
网络
关系型数据库管理系统
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP