问题描述
如何从字符串构造bitset?
例如:
std :: bitset< 16> b16(" 1011011110001011");
这可能吗?
提前致谢。
-haro
是的。你试过RTFMing吗?
是的。你有没有尝试过RTFMing?
如果RTFMing是关于搜索网页,那么是b $ b然后是的,我做了(因为我知道你要去问:))
我正在使用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
Yes. Have you tried RTFMing?
Yes. Have you tried RTFMing?
If RTFMing is about searching the web,
then yes, I did(because I knew you were going to ask:) )
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,简单的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!