I'd just use a std::string
as a parameter. But if you want to pass a std::istringstream
, then you need to pass it explicitly to f
, as the std::istringstream
constructor that takes a std::string
is marked explicit (#2). Example:
f(std::istringstream{"create_customer 1 Ben Finegold"});
The code above constructs a temporary std::istringstream
as the argument, which is then moved into the parameter command
of your function; it uses the move constructor #3 from here.
Note that we don't need the clunky
f(std::istringstream{std::string{"create_customer 1 Ben Finegold"}});
because the const char*
constructor of std::string
is not explicit (#5), and the compiler is allowed to perform at most one implicit user-defined conversion. Therefore in the first code line I posted the string literal "create_customer 1 Ben Finegold"
is converted to a std::string
, which is then used to explicitly construct the temporary std::istringstream
argument, which is then moved into command
.