Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ > Re: Using: bits...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 2 of 3 Topic 45773 of 47032
Post > Topic >>

Re: Using: bitset( string() )

by Pete Becker <pete@[EMAIL PROTECTED] > May 6, 2008 at 07:14 AM

On 2008-05-06 07:02:00 -0400, mathieu <mathieu.malaterre@[EMAIL PROTECTED]
> 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);

-- 
  Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of "The 
Standard C++ Library Extensions: a Tutorial and Reference 
(www.petebecker.com/tr1book)
 




 3 Posts in Topic:
Using: bitset( string() )
mathieu <mathieu.malat  2008-05-06 04:02:00 
Re: Using: bitset( string() )
Pete Becker <pete@[EMA  2008-05-06 07:14:56 
Re: Using: bitset( string() )
mathieu <mathieu.malat  2008-05-06 04:52:01 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri Jul 25 21:20:34 CDT 2008.