Menu question ?

1
2
3
cout << left << setw(5) << "Menu" << right << setw(5) << endl;
cout << left << setw(5) << "Coke..........." << right << setw(5) << 2.10 << endl; 
cout << "Hamburger...... 1.85" << endl;


How do I make Menu look like --------Menu-------- so that they are evenly set??
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iomanip>
#include <iostream>
#include <string>

int main()
{
    const std::size_t width = 20;
    const std::size_t cost_width = 4;
    const std::string menu = "Menu";
    const std::pair<std::string, double> goods[] {{"Coke", 2.1}, {"Hamburger", 1.85}, {"Water", 0.2} };
    const std::pair<int, int> menu_width {(width + menu.size())/2, (width - menu.size() + 1)/2 };

    auto prev = std::cout.fill();
    std::cout << std::fixed << std::setprecision(2) << std::setfill('-');
    std::cout << std::setw(menu_width.first) << menu << std::string(menu_width.second, '-') << '\n';
    std::cout << std::setfill('.') << std::left;
    for(const auto& p: goods)
        std::cout << std::setw(width - cost_width) << p.first << p.second << '\n';
    std::cout.fill(prev);
}
--------Menu--------
Coke............2.10
Hamburger.......1.85
Water...........0.20
Topic archived. No new replies allowed.