A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.tutorialspoint.com/cpp_standard_library/cpp_valarray_resize.htm below:

C++ valarray Resize

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 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


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