You use unique_ptr when ownership is held by a single entity that has complete control of the lifetime of the object. You use shared_ptr when ownership is shared by multiple entities.
In the above example, either one will work, therefore you should prefer unique_ptr, since it has a simpler implementation.
1) The owner of a smart pointer is the block/function in which that pointer is created, right?
2) Yes, it's moving, I just didn't notice it well. Is moving that pointer to another in a different function (main()) not sharing the ownership? Because pn on line 10 and 11 owns the content and prints it.
3) Or how to know where a smart pointer is shared, for instance, to keep matters simple, in the project above?
> Which one should I use for this project
for that particular example, dynamic allocation is not needed
perhaps you should provide a proper example, one that does exemplify your issue.
> The owner of a smart pointer is the block/function in which that pointer is created, right?
¿what do you understand by «owner»?
> Is moving that pointer to another in a different function not sharing the ownership?
when you share, both parties may be able to use the resource
if you are in main(), then foo() already died, so it can't own anything (also, I find weird to say that a function owns something)
> how to know where a smart pointer is shared
¿look at the ref_count?
a shared pointer may be shared
a unique pointer is unique and may not be shared
You should not be using a smart pointer at all here. std::vector<> is a clearly better choice; with move semantics, these can be efficiently returned from a function.