【问题标题】:Tinythread++: getting thread IDTinythread++:获取线程 ID
【发布时间】:2011-03-22 21:11:30
【问题描述】:

这就是您将其打印到终端的方式。

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

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

【问题讨论】:

  • 我在吹毛求疵,但这个问题并不是关于多线程、Tinythread++,也不是获取线程 ID,而是关于 STL 字符串格式。如果你准确地描述你的问题,你真的更有可能得到好的、有用的答案。

标签: c++ string stl


【解决方案1】:

使用 std::stringstream

#include <sstream>

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-12-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多