How do I make a line?
How do I make a line?
I cannot wrap my head around the "setfill()" function.
I just want to make one line, not fill the whole output with '_'
1 2
|
cout << setfill('_') << setw(40) << endl;
cout << setw(20) << "Name" << setw(10) << "Car" << setw(10) << "Salary" << endl;
| |
Hello Fayezilla,
To use "setfill" you started out correctly, but did not finish.
|
cout << setfill('_') << setw(40) << '_' << '\n';
| |
"setfill" changes the fill character, but you have to follow the "setw" with at least 1 character so the rest of the block can be filled.
An alternative I like is the fill ctor of "std::string:
std::cout << std::string(40, '_') << '\n';
Andy
You need to set the fill character back to a space afterwards:
|
cout << setfill('_') << setw(40) << "" << setfill(' ') << '\n';
| |
Thank you!
All I could find online was crazy functions or graphics to create lines
Topic archived. No new replies allowed.