In this tutorial, we will be discussing a program to create a C/C++ code formatting tool with the help of clang tools.
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
最后将此文件复制到当前项目的顶级目录。
立即学习“C++免费学习笔记(深入)”;
现在,您可以使用自己的代码格式化工具。只需运行创建的Python文件,您就可以开始使用了!
以上就是使用Clang工具创建一个C/C++代码格式化工具的详细内容,更多请关注php中文网其它相关文章!
c++怎么学习?c++怎么入门?c++在哪学?c++怎么学才快?不用担心,这里为大家提供了c++速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号