The purpose of shared_ptr and unique_ptr is to make sure that delete is called at correct moment. Alas, they trust that you give them address of dynamically allocated object.
Therefore, your program does essentially:
1 2 3
inti = 19; // not a dynamically allocated object
// something
delete &i; // error
shared_ptrand unique_ptr are for use in dynamically allocated memory pointers or memory allocated on the heap rather than the stack.
Your code allocated i to the stack and then you tried to access it with dynamic memory techniques. The use of the new keyword with the int creation returned a pointer reference to i dynamically created on the heap at which point the std::shared_ptr could work. Here's a link to the documentatin on the newkeyword https://en.cppreference.com/w/cpp/language/new
I'm still learning too and what I'm learning is avoid these kinds of dynamic memory allocations if you can. The Standard Library has some helpful tools to help with that. Otherwise you're going to have to write custom copy constructors, move constructor, copy assignment constructors, move assignment constructor and destructors to delete the dynamic memory allocations. C++ will build all of these things for you but the ones it builds won't always work properly in dynamic memory situations. (From what I've learned so far)