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?
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
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.