Hi,
I'm in a habit of using sprintf in C++.
What in the standard C++ can be use instead? and should I change my ways?
Printable View
Hi,
I'm in a habit of using sprintf in C++.
What in the standard C++ can be use instead? and should I change my ways?
stringstream is the "similar thing". You use it like any other stream, and it's a "two way", so you can do something like:
--Code:int main()
{
stringstream ss;
float f;
string s;
cout << "Enter a float:";
cin >> f;
ss << setw(5) << setprecision(3) << f;
ss >> s;
cout << "string is " << s << endl;
return 0;
}
Mats
Thanks matsp.