Setting width in C++ output stream

后端 未结 3 770
情深已故
情深已故 2020-12-05 11:02

I\'m trying to create a neatly formatted table on C++ by setting the width of the different fields. I can use setw(n), doing something like

cout << set         


        
3条回答
  •  爱一瞬间的悲伤
    2020-12-05 11:27

    I know this is still making the same call, but I know of no other solution from what I am getting from your question.

    #define COUT std::cout.width(10);std::cout<<
    
    int main()
    {
        std::cout.fill( '.' );
    
        COUT "foo" << std::endl;
        COUT "bar" << std::endl;
    
        return 0;
    }
    

    Output:

    ..........foo
    ..........bar
    

提交回复
热议问题