I have to format std::string with sprintf and send it into file stream. How can I do this?
You can format C++ output in cout using iomanip header file. Make sure that you include iomanip header file before you use any of the helper functions like setprecision, setfill etc.
Here is a code snippet I have used in the past to print the average waiting time in the vector, which I have "accumulated".
#include
#include
#include
#include
...
cout<< "Average waiting times for tasks is " << setprecision(4) << accumulate(all(waitingTimes), 0)/double(waitingTimes.size()) ;
cout << " and " << Q.size() << " tasks remaining" << endl;
Here is a brief description of how we can format C++ streams. http://www.cprogramming.com/tutorial/iomanip.html