Using: bitset( string() )

Discussion in 'C++' started by mathieu, May 6, 2008.

  1. mathieu

    mathieu Guest

    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, May 6, 2008
    #1
    1. Advertising

  2. mathieu

    mathieu Guest

    On May 6, 1:14 pm, Pete Becker <> wrote:
    > On 2008-05-06 07:02:00 -0400, mathieu <> 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.
    mathieu, May 6, 2008
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Dill Hole
    Replies:
    2
    Views:
    430
    Mike Wahler
    Jul 5, 2003
  2. Jason

    using a bitset

    Jason, Dec 9, 2003, in forum: C++
    Replies:
    3
    Views:
    675
    Y2KYZFR1
    Dec 9, 2003
  3. Sean Farrow

    using a std::bitset in an iterator

    Sean Farrow, Aug 24, 2008, in forum: C++
    Replies:
    4
    Views:
    927
    Sean Farrow
    Aug 25, 2008
  4. David Garamond

    Getting back a byte string from BitSet

    David Garamond, Feb 18, 2004, in forum: Ruby
    Replies:
    0
    Views:
    121
    David Garamond
    Feb 18, 2004
  5. Ninds
    Replies:
    14
    Views:
    713
    W Karas
    Dec 3, 2012
Loading...

Share This Page