目 录CONTENT

文章目录

Format C++ code in Google style

TalentQ
2025-08-25 / 0 评论 / 0 点赞 / 4 阅读 / 0 字

1 安装 clang-format 工具

pip install clang-format

2 修改 ~/.bashrc

在 ~/.bashrc 中添加以下内容。

# format C++ code in Google style
format() {
    if [ $# -ne 1 ]; then
        echo -e "Usage: \n\tformat <filename>\n"
        return 1
    fi

    if [ ! -f "$1" ]; then
        echo "Error: File '$1' not found."
        return 2
    fi

    clang-format --style=Google -i "$1"
    if [ $? -eq 0 ]; then
        echo "successful"
    else
        echo "failed"
        return 3
    fi
}

3 使用

format xxx.cc

0

评论区