Requirements for a project I'm doing not only require I make a function which returns a string containing the number of a variable but also that the number of that variable is set to a number of decimal points. I have no idea how to do the former or how to do the latter outside of cout with setprecision.
Asked
Active
Viewed 62 times
1 Answers
1
To be honest, it doesn't appear fully clear to me what your assignment actually is. But:
I have no idea how to do the former or how to do the latter outside of cout with setprecision.
So if you know how to do it with std::cout
, then you might use a std::ostringstream
:
std::ostringstream out;
// now use out exactly the same way you would have used std::cout
Note that it's not the only way to get strings, but the one closest to what you are already familiar with...

Aconcagua
- 24,880
- 4
- 34
- 59