setfill(*) and setw() help needed!

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sam142
    New Member
    • Jun 2012
    • 5

    setfill(*) and setw() help needed!

    i want to print like this
    *************** * some text with blank *************** *****
    using setw() and setfill(*) how to to this ?
    and also want to print like this
    some text ***** some text
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    Consider writing a manipulator. These are functions like endl. They have a single ostream& argument and return an ostream&.

    So to display five asterisks you would write:

    Code:
    ostream& FiveStars(ostream& os)
    {
        os << "*****";
        return os;
    }
    Then to use it you code:

    Code:
    cout << FiveStars << "some text with blanks" << FiveStars << endl;
    Of course, since FiveStars is a function of yours you can write code to determine what the fill character is and how many to display, etc...

    Comment

    Working...