Tinythread++: getting thread ID
This is how you get it printed to the terminal.
cout << "Current thread ID: " << this_thread:开发者_如何学Go:get_id() << endl;
Of course when there are multiple threads the output becomes interleaved and impossible to figure out. So I wanted to log each thread's output to its own file. But I need the thread ID to give a name to the file to send to fopen()
. How to use iostream to save thread ID to a string?
Use std::stringstream
#include <sstream>
std::stringstream s;
s << "File_Name:_" << this_thread::get_id();
std::ofstream file(s.str().c_str());
精彩评论