C++ Bitset 中的 to_string()函数

首页 / C++入门教程 / C++ Bitset 中的 to_string()函数

C++位集to_string()函数用于构造一个基本的字符串对象,该对象将位集中的位表示为连续的0和1。

to_string - 语法

string to_string();

to_string - 返回值

它返回一个表示位集中的位的字符串。

链接:https://www.learnfk.comhttps://www.learnfk.com/c++/cpp-bitset-to-string-function.html

来源:LearnFk无涯教程网

to_string - 例子1

#include <iostream>
#include <bitset>
using namespace std;
int main()
{
    bitset<4> b;     
    b.set();              
   string mystring =
   b.to_string<char,string::traits_type,string::allocator_type>();
  cout << "mystring: " << mystring << '\n';
   return 0;
}

输出:

mystring: 1111

祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)

技术教程推荐

重学前端 -〔程劭非(winter)〕

NLP实战高手课 -〔王然〕

用户体验设计实战课 -〔相辉〕

深度学习推荐系统实战 -〔王喆〕

Go 并发编程实战课 -〔晁岳攀(鸟窝)〕

说透芯片 -〔邵巍〕

深入剖析Java新特性 -〔范学雷〕

eBPF核心技术与实战 -〔倪朋飞〕

运维监控系统实战笔记 -〔秦晓辉〕

好记忆不如烂笔头。留下您的足迹吧 :)