How do I make a line?

Jul 8, 2021 at 11:04pm
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; 
Jul 8, 2021 at 11:13pm
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
Jul 8, 2021 at 11:49pm
You need to set the fill character back to a space afterwards:

 
cout << setfill('_') << setw(40) << "" << setfill(' ') << '\n';

Jul 9, 2021 at 12:19am
Thank you!

All I could find online was crazy functions or graphics to create lines
Topic archived. No new replies allowed.