How to resize deques in C++

2 Answers

0 votes
#include <iostream>
#include <deque>

using std::cout;
using std::endl;
using std::deque;

int main()
{
	deque<int> dq{ 1, 2, 3, 4, 5 };

	dq.resize(7);
	
	for (int val : dq)
		cout << val << " ";
	cout << endl;

	return 0;
}

/*
run:

1 2 3 4 5 0 0

*/

 



answered May 4, 2018 by avibootz
0 votes
#include <iostream>
#include <deque>

using std::cout;
using std::endl;
using std::deque;

int main()
{
	deque<int> dq{ 1, 2, 3, 4, 5 };

	dq.resize(6, 999);
	
	for (int val : dq)
		cout << val << " ";
	cout << endl;

	return 0;
}

/*
run:

1 2 3 4 5 999

*/

 



answered May 4, 2018 by avibootz

Related questions

1 answer 115 views
115 views asked May 4, 2018 by avibootz
4 answers 131 views
131 views asked Oct 23, 2025 by avibootz
3 answers 412 views
412 views asked Dec 9, 2020 by avibootz
2 answers 217 views
217 views asked Jul 22, 2020 by avibootz
1 answer 238 views
4 answers 591 views
...