Jump to content
  • Advertisement


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


Alternatives to sprintf?

This topic is 6091 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 remember reading something on the web that you can use cout as an alternative to sprintf. I just can''t remember where I read it. My problem is: Example: char buffer[20]; sprintf(buffer, " %d", 50); TextOut(hdc, 10, 10, buffer, strlen(buffer)); From what I remember you can do something like this: char buffer[20]; cout << 50 << buffer; TextOut(hdc, 10, 10, buffer, strlen(buffer)); But it doesn''t seem to work, can someone tell me what I am doing wrong? Jeff

Share this post

Link to post
Share on other sites
I wouldn''t have thought you could do this. You could use ostringstream. I think this should work (I''m not certain: I haven''t got C++ nearby to test it.)

ostringstream buffer();
buffer << 50;
TextOut(hdc, 10, 10, (LPCTSTR) buffer.str().c_str(), (int) buffer.str().length());

All your bases belong to us (I know. It''s irony.)

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!