public member function
<valarray>
void resize (size_t sz, T c = T());
Resize valarray
Resizes the valarray, changing its length to
sz elements, and assigns the value
c to each element.
After resizing, the array will contain
sz elements with a value of
c, no matter what the previous content was.
All pointers and references to elements of the valarray are invalidated.
Parameters
- sz
- Size of the valarray, in terms of the number of elements.
size_t is an unsigned integral type.
- c
- Value to be assigned to each of the elements of the resized array.
T is the template type of valarray (the elements' type).
Return value
none
Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
// valarray::resize example
#include <iostream>
#include <valarray>
using namespace std;
int increment (int x) {return ++x;}
int main ()
{
valarray<int> myarray (10,5); // 10 10 10 10 10
myarray.resize(3); // 0 0 0
for (size_t n=0; n<myarray.size(); n++)
cout << myarray[n] << ' ';
cout << endl;
return 0;
}
|
Output:
See also
- valarray::size
- Return size (public member function)
- valarray::valarray
- valarray constructor (public member function)
- valarray::operator=
- Assign content (public member function)