Variable sized padding in printf

后端 未结 5 1354
终归单人心
终归单人心 2020-11-30 01:21

Is there a way to have a variable sized padding in printf?

I have an integer which says how large the padding is:

void foo(int paddingSi         


        
5条回答
  •  Happy的楠姐
    2020-11-30 01:47

    better use std::cout

    using namespace std;
    cout << setw(9)                       //set output width
         << setfill('#')                  // set fill character
         << setiosflags(ios_base::right)  //put padding to the left
         << "MyText";
    

    should produce:

    ###MyText
    

提交回复
热议问题