Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


<string> formatting

This topic is 5476 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I''ve recently started using for string operations and am finding it much better than the old C-style. Just one thing though, are there any functions for formatting C++ strings with integers, floats, etc...., the equivalent of the sprintf() function?

Share this post

Link to post
Share on other sites
Yes, look for the stringstream library!

However, the std::string class contains a myString.printf() function too, I think..

Petter Nordlander

"There are only 10 kinds of people in the world. The who understand binary and those who don''t"

Share this post

Link to post
Share on other sites
Hello MessageBox,

there dec, hex, and oct iomanipulators that will set stream to out these.
There is setw set the width of a field
setprecision set number of nuber after .
setfill set what to fill spaces with.

ex float test=234.5678;
cerr << setw(10) << setprecision(2) << setfill(: ) << test << endl;
::::234.57 as an output. I belive it round up on percision but not sure.

Lord Bart

opps it took the : ) as a simliy face

[edited by - lord bart on September 22, 2003 9:10:28 AM]

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!