How can I change the code below to have unique_ptr instead of the traditional pointer?
// vector::data
#include <iostream>
#include <vector>
int main ()
{
std::vector<int> myvector (5);
int* p = myvector.data();
*p = 10;
++p;
*p = 20;
p[2] = 100;
std::cout << "myvector contains:";
for (unsigned i=0; i<myvector.size(); ++i)
std::cout << ' ' << myvector[i];
std::cout << '\n';
return 0;
}
I tried the code below, but I am having E0349 no operator "++" matches these operands
unique_ptr<int> p {myvector.data()};
*p = 10;
++p; // <<< ERROR HERE >>>