std :: bitset,简单的问题 [英] std::bitset, simple question

查看:97
本文介绍了std :: bitset,简单的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从字符串构造bitset?


例如:

std :: bitset< 16> b16(" 1011011110001011");


这可能吗?


提前致谢。

-haro

解决方案

Haro Panosyan写道:

如何从字符串构造一个bitset?

例如:
std :: bitset< 16> b16(" 1011011110001011");

这可能吗?




是的。你试过RTFMing吗?


Victor Bazarov写道:

Haro Panosyan写道:

如何从字符串构造一个bitset?

例如:
std :: bitset< 16> b16(" 1011011110001011");

这可能吗?



是的。你有没有尝试过RTFMing?




如果RTFMing是关于搜索网页,那么是b $ b然后是的,我做了(因为我知道你要去问:))



Victor Bazarov写道:

Haro Panosyan写道:

如何从字符串构造一个bitset?

例如:
std :: bitset< 16> b16(" 1011011110001011");

这可能吗?

是的。您是否尝试过RTFMing?




我正在使用g ++ 3.3.3 for SunOS。这是代码:


#include< bitset>


int main()

{

std :: bitset< 8> b2(" 10101010"); //< - 第5行

返回0;

}

这是错误信息:

g ++ bitset1.cpp -o bitset1



bitset1.cpp:在函数`int main()''中:

bitset1 .cpp:5:错误:从`const char *''无效转换为`long

unsigned

int''

bitset1.cpp :5:错误:初始化参数1的'

std :: bitset< _Nb> :: bitset(long unsigned int)[with unsigned int _Nb = 8]''


How to construct a bitset from string?

For example:
std::bitset<16> b16("1011011110001011");

Is this possible?

Thanks in advance.
-haro

解决方案

Haro Panosyan wrote:

How to construct a bitset from string?

For example:
std::bitset<16> b16("1011011110001011");

Is this possible?



Yes. Have you tried RTFMing?


Victor Bazarov wrote:

Haro Panosyan wrote:

How to construct a bitset from string?

For example:
std::bitset<16> b16("1011011110001011");

Is this possible?


Yes. Have you tried RTFMing?



If RTFMing is about searching the web,
then yes, I did(because I knew you were going to ask:) )



Victor Bazarov wrote:

Haro Panosyan wrote:

How to construct a bitset from string?

For example:
std::bitset<16> b16("1011011110001011");

Is this possible?

Yes. Have you tried RTFMing?



I am using g++ 3.3.3 for SunOS. Here is the code:

#include <bitset>

int main()
{
std::bitset<8> b2("10101010");// <- line 5
return 0;
}
And here is the error message:
g++ bitset1.cpp -o bitset1


bitset1.cpp: In function `int main()'':
bitset1.cpp:5: error: invalid conversion from `const char*'' to `long
unsigned
int''
bitset1.cpp:5: error: initializing argument 1 of `
std::bitset<_Nb>::bitset(long unsigned int) [with unsigned int _Nb = 8]''


这篇关于std :: bitset,简单的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆