Advertisement
RobertDeMilo

WB2.6 Векторы 1

Sep 3rd, 2023 (edited)
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.67 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. using namespace std;
  5.  
  6. void PrintVector(const vector<string>& v)
  7. {
  8.     for (string s : v)
  9.     {
  10.         cout << s << endl;
  11.     }
  12. }
  13.  
  14. int main()
  15. {
  16.     int n;
  17.     cin >> n;
  18.     vector<string> v(n); //конструктор вектора
  19.     for (string& s : v)
  20.     {
  21.         cin >> s;
  22.         cout << "Current size = " << v.size() << endl;
  23.     }
  24. ****************************************************************
  25.     vector <string> v;
  26.     int i = 0;
  27.     while (i < n)
  28.     {
  29.         string s;
  30.         cin >> s;
  31.         v.push_back(s);
  32.         cout << "Current size = " << v.size() << endl;
  33.         ++i;
  34.     }
  35. ****************************************************************
  36.  
  37.     PrintVector(v);
  38.  
  39.     return 0;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement