Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C++ (http://www.velocityreviews.com/forums/f39-c.html)
-   -   Using: bitset( string() ) (http://www.velocityreviews.com/forums/t610969-using-bitset-string.html)

mathieu 05-06-2008 11:02 AM

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

mathieu 05-06-2008 11:52 AM

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.


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57