CPP   117
vector constructors
Guest on 3rd February 2023 01:43:55 AM


  1. #include <iostream>
  2. #include <cassert>
  3. #include <vector>
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.   cout << "Demonstrating simplest vector constructors"
  9.        << endl;
  10.   vector<char> vector1, vector2(3, 'x');
  11.   assert (vector1.size() == 0);
  12.   assert (vector2.size() == 3);
  13.   assert (vector2[0] == 'x' && vector2[1] == 'x' &&
  14.           vector2[2] == 'x');
  15.   assert (vector2 == vector<char>(3, 'x') &&
  16.           vector2 != vector<char>(4, 'x'));
  17.   cout << " --- Ok." << endl;
  18.   return 0;
  19. }

Raw Paste

Login or Register to edit or fork this paste. It's free.