Alrighty, im trying to make a game using Health bars that are illustraed by the following

"Health: |||||||||||||||||"

and i wanted to know if p1Health was my int variable (int p1Health; ) representing player 1's health, how i can make that output the same number of "|"s. So if p1Health = 20, i want the code to output "||||||||||||||||||||".

(I know i could use an 'if' statement or a 'switch:case' but i would like to do it with the least amount of code possible because there is alot more elements to this game, and i don't want the health bar to take up 1000 lines. (there are two players in this game, so the shorter the code the better)

Is there a way i can use my variable p1Health and put it into setw()?
*because setw(p1Health) didnt work.