devxlogo

Initializing a Vector with the Contents of an Array

Initializing a Vector with the Contents of an Array

You can initialize a vector with the contents of a built-in array like this:

 #include#include using namespace std;int main(){  int arr[3];  arr[0] = 4; arr[1] = 8;  arr[2] = 16;   vector  vi ( &arr[0],     // first argument is the address of  the array's beginning                             &arr[3] );    // second argument must point one element past the array's end!   cout

devx-admin

Share the Post: