2011-03-22 36 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());