![]() |
Using: bitset( string() )
Hi there,
I must be doing something wrong, but I do not understand the documentation for bitset( string ), shouldn't this be equivalent (ref == mask ) ? #include <bitset> #include <iostream> #include <string> int main() { std::bitset<8> ref( 13ul ); std::cout << ref << std::endl; const char v[] = "1101"; std::bitset<8> mask( std::string(v) ); std::cout << mask << std::endl; return 0; } Thanks -Mathieu |
Re: Using: bitset( string() )
On May 6, 1:14 pm, Pete Becker <p...@versatilecoding.com> wrote:
> On 2008-05-06 07:02:00 -0400, mathieu <mathieu.malate...@gmail.com> said: > > > #include <bitset> > > #include <iostream> > > #include <string> > > > int main() > > { > > std::bitset<8> ref( 13ul ); > > std::cout << ref << std::endl; > > > const char v[] = "1101"; > > std::bitset<8> mask( std::string(v) ); > > std::cout << mask << std::endl; > > return 0; > > } > > You've stepped into a funky corner of C++ syntax. This code declares > mask to be a function, and the compiler converts its address to a bool > to insert it into a stream. Break up the definition of mask: > > std::string str(v); > std::bitset<8> mask(str); Thanks ! That was it. |
| All times are GMT. The time now is 07:38 AM. |
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.