fork(1) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class World {
  5. private:
  6. static const size_t COLS = 5;
  7. static const size_t ROWS = 9;
  8. char worldarr[COLS][ROWS] =
  9. {
  10. {'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X'}, //the length of these entries are actually
  11. {'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X'}, //50 but I shortened them for the post
  12. {'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X'},
  13. {'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X'},
  14. {'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X'},
  15. };
  16. public:
  17. char* operator[](int indx) {
  18. return worldarr[COLS - (indx + 1)];
  19. }
  20.  
  21. void print() {
  22. for(int c = 0; c < COLS; c++) {
  23. for(int r = 0; r < ROWS; r++) {
  24. std::cout << worldarr[c][r];
  25. }
  26. std::cout << std::endl;
  27. }
  28. }
  29. };
  30.  
  31. int main() {
  32. World w;
  33. w[0][0] = '@';
  34. w.print();
  35.  
  36. return 0;
  37. }
Success #stdin #stdout 0s 5464KB
stdin
Standard input is empty
stdout
XXXXXXXXX
XXXXXXXXX
XXXXXXXXX
XXXXXXXXX
@XXXXXXXX