Advertisement
OHYtheAwesome

Library Arrays

Mar 21st, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.01 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <sstream>
  4. #include <array> //this a new library to use the alternative array
  5. //eclipse seems to consider the library arrays as falsely call the errors which can be annoying for debugging
  6. using namespace std;
  7.  
  8. void titato (string a[][]) { //notice that now you can leave both [] empty
  9.     int n;
  10.     int m;
  11.     string d;
  12.     for ( m = 0; m<a.size(); ++m){ //one advantage of the library array is that you can find its size easily by 'name of array here'.size
  13.         for ( n = 0; n<3; ++n) {
  14.             d = a[m][n];
  15.             cout << d << " ";
  16.         }
  17.         cout << endl;
  18.     }
  19. }
  20.  
  21. int main() {
  22.     array<int,5> numbers = {16, 27, 7, 40, 12071}; //this is another way to declare an array and is more accurate
  23.     int x = numbers[0];
  24.     int n;
  25.     array<array<int,3>,3> tic = {{"x", "o", "x"}, {"x", "o", "x"}, {"o", "x", "o"}};
  26.     cout << x << endl;
  27.     numbers[0] = 1;
  28.     x = numbers[0];
  29.     cout << x << endl;
  30.     for ( n=0 ; n<numbers.size() ; ++n ) {
  31.         cout << numbers[n] << " " << endl;
  32.       }
  33.     titato(tic);
  34.     return 0;
  35.  
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement