Source of TestStuff20141022.cpp


  1: //TestStuff20141022.cpp

  2: //Wednesday, October 22, 2014

  3: 
  4: #include <iostream>

  5: #include <vector>

  6: #include <algorithm>

  7: using namespace std;
  8: 
  9: #include "utilities.h"

 10: using Scobey::Pause;
 11: using Scobey::RandomGenerator;
 12: 
 13: 
 14: int main(int argc, char* argv[])
 15: {
 16:     //int i = 6;

 17:     //cout << sizeof (i) << endl;

 18:     //cout << sizeof i << endl; //parentheses optional if argument is a variable

 19:     //cout << sizeof (int) << endl; //need parentheses if a type is the argument

 20:     //int a[] = { 1, 2, 3 };

 21:     //cout << sizeof a << endl;

 22:     //cout << (sizeof a) / sizeof(int) << endl;

 23:     //cout << endl;

 24: 
 25:     //The old (pre-C++11) way:

 26:     //int a[] = { 2, 4, 6, 8, 10 };

 27:     //vector<int> v(a, a + 5);

 28:     //for (vector<int>::size_type i = 0; i < v.size(); i++)

 29:     //    cout << v.at(i) << " ";

 30:     //cout << endl;

 31: 
 32:     //The new (C++11) way using "uniform initialization"

 33:     //and a "range for-loop":

 34:     //vector<int> v{ 2, 4, 6, 8, 10 };

 35:     //for (int i : v) cout << i << " ";

 36:     //cout << endl;

 37: 
 38:     //The iterator (pre-C++11 and post-C++11) way:

 39:     //vector<int> v{ 2, 4, 6, 8, 10 };

 40:     //for (vector<int>::iterator i = v.begin(); i < v.end(); i++)

 41:     //    cout << *i << " ";

 42:     //cout << endl;

 43:     //for (vector<int>::reverse_iterator i = v.rbegin(); i < v.rend(); i++)

 44:     //    cout << *i << " ";

 45:     //cout << endl;

 46: 
 47:     //The iterator way with keyword auto (auto only post-C++11):

 48:     //(auto used as a type in this way causes C++ to give to the

 49:     //variable declared as "auto" the type of the value assigned to it)

 50:     //vector<int> v{ 2, 4, 6, 8, 10 };

 51:     //for (auto i = v.begin(); i < v.end(); i++)

 52:     //    cout << *i << " ";

 53:     //cout << endl;

 54:     //for (auto i = v.rbegin(); i < v.rend(); i++)

 55:     //    cout << *i << " ";

 56:     //cout << endl;

 57:     //for (auto i = v.rbegin()+1; i < v.rend()-2; i++)

 58:     //    cout << *i << " ";

 59:     //cout << endl;

 60: 
 61:     vector<int> v{ 2, 4, 6, 8, 10 };
 62:     vector<int> v1(v.begin() + 1, v.end() - 2);
 63:     for (auto i = v1.begin(); i < v1.end(); i++)
 64:         cout << *i << " ";
 65: 
 66: 
 67: 
 68: }
 69: 
 70: