public member function
<valarray>
std::valarray::resizevoid resize (size_t sz, T c = T());
Resize valarray
Resizes the valarray, changing its size to sz elements, and assigns the value c to each element.After resizing, the previous contents are lost: the valarray will contain sz elements, all of them with a value of c.
All pointers and references to elements of the valarray are invalidated by the call.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
// valarray::resize example
#include <iostream> // std::cout
#include <cstddef> // std::size_t
#include <valarray> // std::valarray
int increment (int x) {return ++x;}
int main ()
{
std::valarray<int> myarray (10,5); // 10 10 10 10 10
myarray.resize(3); // 0 0 0
std::cout << "myvalarray contains:";
for (std::size_t n=0; n<myarray.size(); n++)
std::cout << ' ' << myarray[n];
std::cout << '\n';
return 0;
}
myvalarray contains: 0 0 0
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4