Tinythread ++:获取线程ID

时间:2011-03-22 21:11:30

标签: c++ string stl

这是将它打印到终端的方式。

cout << "Current thread ID: " << this_thread::get_id() << endl;

当然,当有多个线程时,输出会交错并且无法弄清楚。所以我想将每个线程的输出记录到自己的文件中。但是我需要线程ID来为要发送给fopen()的文件命名。如何使用iostream将线程ID保存到字符串?

1 个答案:

答案 0 :(得分:3)

使用std :: stringstream

#include <sstream>

std::stringstream s;
s << "File_Name:_" << this_thread::get_id();

std::ofstream file(s.str().c_str());
相关问题