Alternatives to sprintf?

Started by
0 comments, last by jthdmb10 22 years, 5 months ago
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
Advertisement
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.)
CoV

This topic is closed to new replies.

Advertisement