unique pointer

I made this code here:

#include <functional>
#include <iostream>

#include "to_c_array.h"

void to_c_array(){

}

int main() {

// Please note: this excercise is for educational purposes.
// You should allways use std:: container classes such as std::vector when
// possible.

std::vector<int> v1(10, 1.0);
std::unique_ptr<int[]> p1 = to_c_array(v1);
for (std::size_t i = 0; i < v1.size(); i++)
std::cout << p1[i] << " ";
std::cout << std::endl;

return 0;
}

i want to make a function that will give an output of

1 1 1 1 1 1 1 1 1 1
Last edited on
i want to make a function that will give an output of

What does this have to do with "unique pointer"?

What exactly are you trying to do?

Do you realize that your vector has 10 elements with the first initialized to 1 and the rest default initialized?

@jlb, no, they will all be set to 1 (although he should say 1 and not 1.0).
See number 2 here: https://en.cppreference.com/w/cpp/container/vector/vector
Last edited on
Topic archived. No new replies allowed.