fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <iomanip>
  4. #include <array>
  5.  
  6. int main()
  7. {
  8. std::array<std::string, 7> fields = {"Name ", "Hours worked", "Pay rate",
  9. "Gross Pay", "Social Security", "Income Tax", "Net Pay"};
  10. std::cout << std::left;
  11. for(const auto& f: fields)
  12. std::cout << std::setw(f.length() + 2) << f;
  13. std::cout << std::right << std::setfill('-') << std:: endl;
  14. for(const auto& f: fields)
  15. std::cout << std::setw(f.length() + 2) << " ";
  16. }
  17.  
Success #stdin #stdout 0s 3428KB
stdin
Standard input is empty
stdout
Name        Hours worked  Pay rate  Gross Pay  Social Security  Income Tax  Net Pay  
----------  ------------  --------  ---------  ---------------  ----------  -------