开发者

Tinythread++: getting thread ID

开发者 https://www.devze.com 2023-02-19 15:00 出处:网络
This is how you get it printed to the terminal. cout << \"Current thread ID: \" << this_thread:开发者_如何学Go:get_id() << endl;

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());
0

精彩评论

暂无评论...
验证码 换一张
取 消