• ### Popular Now

• 15
• 15
• 11
• 9
• 10

#### Archived

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

# Alternatives to sprintf?

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

## 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 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.)