devxlogo

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<< vi[0] << '	' << vi[1] << '	' << vi[2] <

Charlie has over a decade of experience in website administration and technology management. As the site admin, he oversees all technical aspects of running a high-traffic online platform, ensuring optimal performance, security, and user experience.

See also  How Engineering Leaders Spot Weak Proposals

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.