M
Mike Chirico
Sorry about the newbie question. What's the best way to convert
numbers to strings in C++. The following works, but is it better than
using the sprintf() "old C" way of converting?
#include <iostream>
#include <string>
#include <sstream>
#include <list>
using namespace std;
int main(void)
{
list<string> ml;
string s;
stringstream ss;
for(int i=0; i < 3000; ++i)
{
ss << "sample text " << i ;
ml.push_front( ss.str() );
ss.str("");
}
cout << ml.front() << endl;
}
What about the fact that the stringstream has to be cleared
ss.str("")...does that incur additional overhead? Maybe there is a
better way?
Regards,
Mike Chirico
numbers to strings in C++. The following works, but is it better than
using the sprintf() "old C" way of converting?
#include <iostream>
#include <string>
#include <sstream>
#include <list>
using namespace std;
int main(void)
{
list<string> ml;
string s;
stringstream ss;
for(int i=0; i < 3000; ++i)
{
ss << "sample text " << i ;
ml.push_front( ss.str() );
ss.str("");
}
cout << ml.front() << endl;
}
What about the fact that the stringstream has to be cleared
ss.str("")...does that incur additional overhead? Maybe there is a
better way?
Regards,
Mike Chirico