首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >clang-format不会修改磁盘上的文件

clang-format不会修改磁盘上的文件
EN

Stack Overflow用户
提问于 2021-09-05 01:53:43
回答 2查看 132关注 0票数 0

我有以下格式错误的文件,test.cpp

代码语言:javascript
复制
#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。这将正确地识别由于终端上的错误格式和输出而将被更改的点:

代码语言:javascript
复制
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时,我获得了正确格式化的文件的外观(此显示在终端上):

代码语言:javascript
复制
#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继续并应用其更改并将文件保存在磁盘上?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2021-09-05 02:07:37

来自man clang-format

代码语言:javascript
复制
       -i                         - Inplace edit <file>s, if specified.
票数 2
EN

Stack Overflow用户

发布于 2021-09-05 02:09:22

使用-i选项,即Inplace edit <file>s。它将在适当的位置编辑文件。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69060087

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档