学无先后,达者为师

网站首页 编程语言 正文

遍历 bitset 中为 true 的下标

作者:xhchen2023 更新时间: 2023-10-15 编程语言

一个例子:

bitset<5> s("10110");
for (int i = s._Find_first(); i < s.size(); i = s._Find_next(i)) {
    cout << i << " ";
}
//out : 
//1 2 4

s._Find_first()返回s 中第一个为 true 的下标,若不存在则返回 s 的长度。s._Find_first(i)返回 s 中下标 i 之后的第一个为 true 的下标,若不存在则返回 s 的长度。

原文链接:https://blog.csdn.net/weixin_40519680/article/details/132696387

  • 上一篇:没有了
  • 下一篇:没有了
栏目分类
最近更新