Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- using namespace std;
- ****************************************************************
- void PrintVector(const vector<int>& v)
- {
- for (auto s : v)
- {
- cout << s << endl;
- }
- }
- ****************************************************************
- void PrintVector(const vector<bool>& v)
- {
- int i = 0;
- for (auto s : v)
- {
- cout << i << ": " << s << endl;
- ++i;
- }
- }
- ****************************************************************
- int main()
- {
- vector<int> days_in_months = { 31, 28,31,30,31 };
- if (true) // if year is leap
- {
- days_in_months[1]++;
- }
- PrintVector(days_in_months);
- ****************************************************************
- vector <bool> is_holiday(28, false); //по умолчанию заполним вектор значением false
- is_holiday[22] = true;
- PrintVector(is_holiday);
- ****************************************************************
- //is_holiday.resize(31); // оставил нетронутым исходную часть вектора
- is_holiday.assign(31,false);
- is_holiday[7] = true;
- PrintVector(is_holiday);
- is_holiday.clear();
- return 0;
- }
- assign заменяет содержимое контейнера.
- Основное различие между методами `resize` и `assign` заключается в том, что `resize` меняет размер вектора, сохраняя первоначальные значения или инициализируя новые значения, а `assign` изменяет все элементы вектора, заменяя их новыми значениями.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement