To explain that the problem is actually ...
While the compiler is happy to organize the conversion of a char *
/ C string to std::string
using the appropriate std::string
constructor, this is not what you requested.
You requested a pointer to an existing std::string
object. By definition, what is passed to your function should be the address of an existing std::string
(or stream) object.
You should understand pointers as a separate type - your function accepts a pointer-to-std::string
object. While std::string
can be obtained using a pointer to std::string
, the pointer itself is not std::string
, and it cannot be "converted" to std::string
, and it cannot be considered as a pointer to a pointer, char (or vice versa).
The simplest option is a constant reference to std::string
( const std::string &
). const, in this case, because you are not doing anything to change the line. If you were, that would be a different matter, and you would need to carefully consider whether you want the caller to visit your changes.
Having done this, you say that you want the std::string
object (remember, the reference to the object is an object, see C ++ FAQ 8.5 in particular), which allows the compiler to call the appropriate constructor to create std :: string for you, when the function is called using char *
(const or not).
At the same time, if someone passes you the actual std::string
, the constructor is avoided, and you get the same efficiency as if you took pointer-to-std::string
. Win-win.
As an alternative, of course, you can just take a simple std::string
, but in this case you always get a copy of the transmitted string, whether it be a C-string or std::string
. Sometimes it is desirable, sometimes not. In your case, you do nothing except print a line, making unnecessary overhead.