Skip to main content
gamedev.net
🔒 Locked

printing to a buffer

Started by UntalkativeMonkey Apr 21, 2003 at 7:40 PM 2 replies 250+ views
Original Post
UntalkativeMonkey
UntalkativeMonkey
In C, I would do something like this... sprintf(buffer, "blah blah %d", i); Is there a more C++ way of doing it?
Nytegard
Nytegard

    
#include <iostream>

#include <string>

#include <sstream>


using namespace std;


int main()
{
ostringstream cppsprintf;
string somestring;

int someint = 9;

cppsprintf << "The world is my "<< someint << ".";

somestring = cppsprintf.str();
cout << somestring << endl;
return 0;
}



If you like sprintf though, no reason why you shouldn't use it. If it works, it works.

[edited by - Nytegard on April 21, 2003 9:04:18 PM]
UntalkativeMonkey
UntalkativeMonkey
Thanks pal, I guess I was just curious. sprintf() does seem easier to use.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.