fork download
  1. #include <stdio.h>
  2. #include <iostream>
  3. #include <iomanip>
  4.  
  5. using namespace std;
  6.  
  7. struct Item
  8. {
  9. const char * name;
  10. int price;
  11. } item[3] =
  12. {
  13. { "short", 1 },
  14. { "middle long", 250 },
  15. { "very very very long", 3000 }
  16. };
  17.  
  18.  
  19. int main(int argc, char * argv[])
  20. {
  21. cout << "#\tProduct\t\tPrice\n";
  22. for(int i = 0; i < 3; ++i)
  23. cout << i+1 << "\t" << item[i].name << "\t\t"
  24. << item[i].price << "\n";
  25.  
  26. cout << "----------------\n";
  27. cout << left << setw(5) << "#" << setw(22) << "Product" << setw(5) << "Price\n";
  28. for(int i = 0; i < 3; ++i)
  29. cout << left << setw(5) << i+1 << setw(22) << item[i].name << setw(5)
  30. << right << item[i].price << "\n";
  31.  
  32. cout << "----------------\n";
  33.  
  34. printf("# Product Price\n");
  35. for(int i = 0; i < 3; ++i)
  36. printf("%1d %-22s%5d\n",i+1,item[i].name,item[i].price);
  37.  
  38. }
  39.  
Success #stdin #stdout 0.01s 5444KB
stdin
Standard input is empty
stdout
#	Product		Price
1	short		1
2	middle long		250
3	very very very long		3000
----------------
#    Product               Price
1    short                     1
2    middle long             250
3    very very very long    3000
----------------
#    Product               Price
1    short                     1
2    middle long             250
3    very very very long    3000