Archived

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

jthdmb10

Alternatives to sprintf?

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