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 192 views
192 views asked May 4, 2018 by avibootz
4 answers 396 views
396 views asked Oct 23, 2025 by avibootz
3 answers 557 views
557 views asked Dec 9, 2020 by avibootz
2 answers 321 views
321 views asked Jul 22, 2020 by avibootz
1 answer 328 views
4 answers 837 views
...