2011-03-22 41 views
1

这是如何让它打印到终端。Tinythread ++:获取线程ID

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

当然,当有多个线程输出变得交错,并且不可能找出。所以我想将每个线程的输出记录到它自己的文件中。但我需要线程ID给文件的名称发送到fopen()。如何使用iostream将线程ID保存到字符串?

+1

我挑剔,但这个问题是不是真正的多线程,Tinythread ++,也没有得到一个线程ID,它是关于STL字符串格式化。如果你准确地描述你的问题,你真的更有可能得到好的,有用的答案。 – 2011-03-23 00:30:33

回答

3

使用std :: stringstream的

#include <sstream> 

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

std::ofstream file(s.str().c_str());