Programming Tips - clang-format: How to run it

Date: 2020jul8 Language: C/C++ Keywords: auto-format your code Language: bash Q. clang-format: How to run it A. If you want to use the Google C++ Style: https://google.github.io/styleguide/cppguide.html Run it this way:
clang-format -style '{BasedOnStyle: Google, DerivePointerBinding: false, Standard: Cpp11}' -i myfile.cpp myfile_fmt.cpp
Where myfile.cpp is your file to be formatted. And myfile_fmt.cpp is your file after its been re-formatted. Of course there are other style options. See:
clang-format --help
for more info. I made a small script to run it:
#!/bin/sh if [[ $# -lt 1 ]]; then echo "Usage: cfmt <cpp-files>" exit 1 fi FILES=$* STYLE='{BasedOnStyle: Google, DerivePointerBinding: false, Standard: Cpp11}' clang-format -style "$STYLE" -i $FILES