Centering strings with printf()

前端 未结 7 1280
挽巷
挽巷 2020-12-01 10:33

By default, printf() seems to align strings to the right.

printf(\"%10s %20s %20s\\n\", \"col1\", \"col2\", \"col3\");
/*       col1                     


        
7条回答
  •  借酒劲吻你
    2020-12-01 11:12

    There is no printf() format specifier to centre text.

    You will need to write your own function or locate a library which provides the functionality that you're looking for.

提交回复
热议问题