i got no suitable convertion right her "std::istream_iterator"<std::string>(std::istringstream(nb))

const std::string nb = "eight one six eight three three eight five four two nine six nine";
std::transform(std::istream_iterator<std::string>(std::istringstream(nb)),
std::istream_iterator<std::string>(),
std::ostream_iterator<int>(std::cout),
[&numbers](const std::string& word) {
[&word](const Pube& p) {
return p.str == word;
}
)->num;
}
);
}
i got no suitable convertion right her "std::istream_iterator"<std::string>(std::istringstream(nb))
In
std::istream_iterator<std::string>(std::istringstream(nb))
the expression
std::istringstream(nb)
is an rvalue, which is disallowed because it is error prone. For example, if it compiled, the declaration
std::istream_iterator<std::string> it(std::istringstream(nb));
would declare it a dangling iterator because the stream being traversed is destroyed at the semicolon.

To fix the problem, declare the stream on a prior line. The stream argument must be an lvalue expression. For example,
1
2
std::istringstream ss(nb)
std::transform(std::istream_iterator<std::string>{ss}, /* etc... */

Last edited on
thank you mbozzi it works and great reason explanation
Last edited on
Topic archived. No new replies allowed.