我有以下格式错误的文件,test.cpp
#include "maininclude.h"
int main() {
class SIMPLE smpl;
for (int i = 1; i < 100;
i++) {
printf("Printing %d", i); // Trying out different stuff...
getchar();
}
}我想在其上运行clang-format。在运行这段代码之前,为了直观地查看将要修改的位置,我运行了clang-format -n test.cpp。这将正确地识别由于终端上的错误格式和输出而将被更改的点:
test.cpp:3:13: warning: code should be clang-formatted [-Wclang-format-violations]
int main() {
^
test.cpp:5:27: warning: code should be clang-formatted [-Wclang-format-violations]
for (int i = 1; i < 100;
^
test.cpp:6:9: warning: code should be clang-formatted [-Wclang-format-violations]
i++) {
^
test.cpp:7:64: warning: code should be clang-formatted [-Wclang-format-violations]
printf("Printing %d", i); // Trying out different stuff...
^在运行clang-format test.cpp时,我获得了正确格式化的文件的外观(此显示在终端上):
#include "maininclude.h"
int main() {
class SIMPLE smpl;
for (int i = 1; i < 100; i++) {
printf("Printing %d", i); // Trying out different stuff...
getchar();
}
}但是,运行上述命令并不会更改磁盘上的实际test.cpp文件。是否有一个单独的选项/命令让clang-format继续并应用其更改并将文件保存在磁盘上?
发布于 2021-09-05 02:07:37
来自man clang-format
-i - Inplace edit <file>s, if specified.发布于 2021-09-05 02:09:22
使用-i选项,即Inplace edit <file>s。它将在适当的位置编辑文件。
https://stackoverflow.com/questions/69060087
复制相似问题