-3

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.

August A.
  • 3
  • 1
  • 1
    Does this maybe help? https://stackoverflow.com/questions/2872543/printf-vs-cout-in-c/20238349 or http://www.cplusplus.com/reference/cstdio/printf/ – petrch Nov 17 '18 at 08:26

1 Answers1

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