Why does the following not work?
Posted
by Dony
on Stack Overflow
See other posts from Stack Overflow
or by Dony
Published on 2010-03-29T16:00:24Z
Indexed on
2010/03/29
16:03 UTC
Read the original article
Hit count: 288
c++
Hi, I tried to make the code #1 more terse by changing it to code #2 but it doesn't work as expected. Can anyone please tell me why it doesn't work? Thanks.
Code #1
std::ostringstream q0;
q0 << "(" << x << "," << y << "," << z << ")";
std::string s = q0.str();
Code #2
double x = 8.9, y = 3.4, z = -4.5;
std::string s = static_cast<std::ostringstream &>(
std::ostringstream() << "(" << x << "," << y << "," << z << ")").str();
© Stack Overflow or respective owner