Suppose I have a multiset of integers and I want to insert 3, n times into the multiset. I can obviously do it using a for loop but is there any other way to do it using some function in the stl?
Asked
Active
Viewed 202 times
1 Answers
0
One approach:
// Assuming n is not known at compile time
int* array = new int[n];
// Set all elements of array to value 3
std::fill_n(array, n, 3);
// Create multiset using array to initialize it
std::multiset<int> myMultiSet(array, array + n);
// Free memory
delete[] array;

GigaRohan
- 747
- 2
- 8
- 21