bitset Multiple Values Assignment

Discussion in 'C++' started by Mike Copeland, Jun 11, 2012.

  1. Is there syntax that allows me to assign multiple bitset values at
    runtime? Specifically, I have declared the following:

    bitset<128> valGenders;

    and I wish to assign default values during execution. I know that I can
    do this:

    bitset<128> numDights (string("-.0123456789"));

    but because valGenders is defined in a structure that's allocated during
    runtime I cannot use this syntax. I wish to assign all the bits for the
    characters "MmFf" as a default set when I allocate a structure member,
    but I can't find anything that shows how.
    Or must I run through 4 individual valGenders.set() calls? 8<{{
    Please advise. TIA
    Mike Copeland, Jun 11, 2012
    #1
    1. Advertising

  2. Mike Copeland

    Luca Risolia Guest

    On 11/06/2012 02:07, Mike Copeland wrote:
    > Is there syntax that allows me to assign multiple bitset values at
    > runtime? Specifically, I have declared the following:
    >
    > bitset<128> valGenders;
    >
    > and I wish to assign default values during execution. I know that I can
    > do this:
    >
    > bitset<128> numDights (string("-.0123456789"));


    You cannot do that. The constructor will throw a std::invalid_argument
    exception, since the string contains characters different from "0" and "1".

    >
    > but because valGenders is defined in a structure that's allocated during
    > runtime I cannot use this syntax. I wish to assign all the bits for the
    > characters "MmFf" as a default set when I allocate a structure member,
    > but I can't find anything that shows how.
    > Or must I run through 4 individual valGenders.set() calls? 8<{{
    > Please advise. TIA


    Your problem is not very clear. Why cannot you just initialize the
    bitset data member in the constructor initialization list of the struct?
    Luca Risolia, Jun 11, 2012
    #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. Andy Skypeck

    bitset assignment

    Andy Skypeck, Dec 3, 2003, in forum: C++
    Replies:
    2
    Views:
    1,859
    Dan W.
    Dec 3, 2003
  2. nagy
    Replies:
    36
    Views:
    1,004
    Terry Reedy
    Jul 20, 2006
  3. Allen
    Replies:
    9
    Views:
    1,598
    Bertrand
    Jan 26, 2009
  4. bbrady
    Replies:
    2
    Views:
    949
    bbrady
    Jan 27, 2010
  5. Ninds
    Replies:
    14
    Views:
    739
    W Karas
    Dec 3, 2012
Loading...

Share This Page