- The C Standard Library
- The C Standard Library
- The C++ Standard Library
- C++ Library - Home
- C++ Library - <fstream>
- C++ Library - <iomanip>
- C++ Library - <ios>
- C++ Library - <iosfwd>
- C++ Library - <iostream>
- C++ Library - <istream>
- C++ Library - <ostream>
- C++ Library - <sstream>
- C++ Library - <streambuf>
- C++ Library - <atomic>
- C++ Library - <complex>
- C++ Library - <exception>
- C++ Library - <functional>
- C++ Library - <limits>
- C++ Library - <locale>
- C++ Library - <memory>
- C++ Library - <new>
- C++ Library - <numeric>
- C++ Library - <regex>
- C++ Library - <stdexcept>
- C++ Library - <string>
- C++ Library - <thread>
- C++ Library - <tuple>
- C++ Library - <typeinfo>
- C++ Library - <utility>
- C++ Library - <valarray>
- The C++ STL Library
- C++ Library - <array>
- C++ Library - <bitset>
- C++ Library - <deque>
- C++ Library - <forward_list>
- C++ Library - <list>
- C++ Library - <map>
- C++ Library - <queue>
- C++ Library - <set>
- C++ Library - <stack>
- C++ Library - <unordered_map>
- C++ Library - <unordered_set>
- C++ Library - <vector>
- C++ Library - <algorithm>
- C++ Library - <iterator>
- C++ Programming Resources
- C++ Programming Tutorial
- C++ Useful Resources
- C++ Discussion
C++ valarray Library - Function resize
Description
It resizes the valarray, changing its size to sz elements, and assigns the value c to each element.
Declaration
Following is the declaration for std::valarray::resize function.
void resize (size_t sz, T c = T());
C++11
void resize (size_t sz, T c = T());
Parameters
sz − It is used to find size of the valarray.
c − It is a value to be assigned to each of the elements of the resized array.
Return Value
none
Exceptions
Basic guarantee − if any operation performed on the elements throws an exception.
Data races
All elements effectively copied are accessed.
Example
In below example explains about std::valarray::resize function.
#include <iostream> #include <cstddef> #include <valarray> int increment (int x) {return ++x;} int main () { std::valarray<int> myarray (100,50); myarray.resize(3); std::cout << "myvalarray contains:"; for (std::size_t n=0; n<myarray.size(); n++) std::cout << ' ' << myarray[n]; std::cout << '\n'; return 0; }
Let us compile and run the above program, this will produce the following result −
myvalarray contains: 0 0 0
valarray.htm
Advertisements