operator<<(std::thread::id)
来自cppreference.com
在标头 <thread> 定义
|
||
template< class CharT, class Traits > std::basic_ostream<CharT,Traits>& |
(C++11 起) | |
将线程标识符 id 的文本表示写入输出流 ost。
若两个线程标识符比较相等,则它们拥有相同的文本表示;若它们比较不相等,则它们的表示有别。
参数
ost | - | 要插入数据的输出流 |
id | - | 线程标识符 |
返回值
ost
异常
可能会抛出由实现定义的异常。
示例
运行此代码
#include <chrono> #include <iostream> #include <thread> using namespace std::chrono; int main() { std::thread t1([]{ std::this_thread::sleep_for(256ms); }); std::thread t2([]{ std::this_thread::sleep_for(512ms); }); std::clog << t1.get_id() << '\n' << t2.get_id() << '\n'; t1.join(); t2.join(); }
可能的输出:
141592653589793 141421356237309