📄 bitset.html
字号:
<TR>
<TD VAlign=top>
<tt>bitset operator&(const bitset&, const bitset&)</tt>
</TD>
<TD VAlign=top>
<tt>bitset</tt>
</TD>
<TD VAlign=top>
Bitwise and of two bitsets. This is a global function,
not a member function.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>bitset operator|(const bitset&, const bitset&)</tt>
</TD>
<TD VAlign=top>
<tt>bitset</tt>
</TD>
<TD VAlign=top>
Bitwise or of two bitsets. This is a global function,
not a member function.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>bitset operator^(const bitset&, const bitset&)</tt>
</TD>
<TD VAlign=top>
<tt>bitset</tt>
</TD>
<TD VAlign=top>
Bitwise exclusive or of two bitsets. This is a global function,
not a member function.
</TD>
</TR>
<TR>
<TD VAlign=top>
<pre>
template <class Char, class Traits,
size_t N>
basic_istream<Char,Traits>&
operator>>(basic_istream<Char,Traits>&,
bitset<N>&)
</pre>
</TD>
<TD VAlign=top>
<tt>bitset</tt>
</TD>
<TD VAlign=top>
Extract a <tt>bitset</tt> from an input stream.
</TD>
</TR>
<TR>
<TD VAlign=top>
<pre>
template <class Char, class Traits,
size_t N>
basic_ostream<Char,Traits>&
operator>>(basic_ostream<Char,Traits>&,
const bitset<N>&)
</pre>
</TD>
<TD VAlign=top>
<tt>bitset</tt>
</TD>
<TD VAlign=top>
Output a <tt>bitset</tt> to an output stream.
</TD>
</tr>
</table>
<h3>New members</h3>
These members are not defined in the
<A href="Assignable.html">Assignable</A>, <A href="DefaultConstructible.html" tppabs="http://www.sgi.com/Technology/STL/DefaultConstructible.shtml">Default Constructible</A>, or <A href="EqualityComparable.html" tppabs="http://www.sgi.com/Technology/STL/EqualityComparable.shtml">Equality Comparable</A>
requirements, but are specific to <tt>bitset</tt>.
<Table border>
<TR>
<TH>
Member
</TH>
<TH>
Description
</TH>
</TR>
<TR>
<TD VAlign=top>
<tt>reference</tt>
</TD>
<TD VAlign=top>
A proxy class that acts as a reference to a single bit. It contains
an assignment operator, a conversion to <tt>bool</tt>, an <tt>operator~</tt>, and
a member function <tt>flip</tt>. It exists only as a helper class for
<tt>bitset</tt>'s <tt>operator[]</tt>. That is, it supports the expressions
<tt>x = b[i]</tt>, <tt>b[i] = x</tt>, <tt>b[i] = b[j]</tt>, <tt>x = ~b[i]</tt>, and
<tt>b[i].flip()</tt>. (Where <tt>b</tt> is a <tt>bitset</tt> and <tt>x</tt> is a <tt>bool</tt>.)
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>bitset(unsigned long val)</tt>
</TD>
<TD VAlign=top>
Conversion from unsigned long. Constructs a bitset, initializing
the first <tt>min(N, sizeof(unsigned long) * CHAR_BIT)</tt> bits to the
corresponding bits in <tt>val</tt> and all other bits, if any, to zero.
</TD>
</TR>
<TR>
<TD VAlign=top>
<pre>
template<class Char, class Traits, class Alloc>
explicit
bitset(const <A href="basic_string.html">basic_string</A><Char,Traits,Alloc>& s,
size_t pos = 0,
size_t n =
<A href="basic_string.html">basic_string</A><Char,Traits,Alloc>::npos)
</pre>
</TD>
<TD VAlign=top>
Conversion from string. Constructs a bitset, initializing the
first <tt>M</tt> bits to the corresponding characters in <tt>s</tt>, where
<tt>M</tt> is defined as <tt>min(N, min(s.size() - pos, n))</tt>.
Note that the <i>highest</i> character position in <tt>s</tt>, not the
lowest, corresponds to the least significant bit.
That is, character position <tt>pos + M - 1 - i</tt> corresponds to bit <tt>i</tt>.
So, for example, <tt>bitset(string("1101"))</tt> is the same as
<tt>bitset(13ul)</tt>. This function throws <tt>out_of_range</tt> if
<tt>pos > s.size()</tt>, and <tt>invalid_argument</tt> if any of the characters
used to initialize the bits are anything other than <tt>0</tt> or <tt>1</tt>.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>bitset& operator&=(const bitset&)</tt>
</TD>
<TD VAlign=top>
Bitwise and.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>bitset& operator|=(const bitset&)</tt>
</TD>
<TD VAlign=top>
Bitwise inclusive or.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>bitset& operator^=(const bitset&)</tt>
</TD>
<TD VAlign=top>
Bitwise exclusive or.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>bitset& operator<<=(size_t n)</tt>
</TD>
<TD VAlign=top>
Left shift, where bit <tt>0</tt> is considered the least significant bit.
Bit <tt>i</tt> takes on the previous value of bit <tt>i - n</tt>, or zero if no
such bit exists.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>bitset& operator>>=(size_t n)</tt>
</TD>
<TD VAlign=top>
Right shift, where bit <tt>0</tt> is considered the least significant bit.
Bit <tt>i</tt> takes on the previous value of bit <tt>i + n</tt>, or zero if no
such bit exists.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>bitset operator<<(size_t n) const</tt>
</TD>
<TD VAlign=top>
Returns a copy of <tt>*this</tt> shifted left by <tt>n</tt> bits.
Note that the expression <tt>b << n</tt> is equivalent to
constructing a temporary copy of <tt>b</tt>
and then using <tt>operator<<=</tt>.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>bitset operator>>(size_t n) const</tt>
</TD>
<TD VAlign=top>
Returns a copy of <tt>*this</tt> shifted right by <tt>n</tt> bits.
Note that the expression <tt>b >> n</tt> is equivalent to
constructing a temporary copy of <tt>b</tt>
and then using <tt>operator>>=</tt>.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>bitset& set()</tt>
</TD>
<TD VAlign=top>
Sets every bit.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>bitset& flip()</tt>
</TD>
<TD VAlign=top>
Flips the value of every bit.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>bitset operator~() const</tt>
</TD>
<TD VAlign=top>
Returns a copy of <tt>*this</tt> with all of its bits flipped.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>bitset& reset()</tt>
</TD>
<TD VAlign=top>
Clears every bit.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>bitset& set(size_t n, int val = 1)</tt>
</TD>
<TD VAlign=top>
Sets bit <tt>n</tt> if <tt>val</tt> is nonzero, and clears bit <tt>n</tt> if <tt>val</tt> is zero.
Throws <tt>out_of_range</tt> if <tt>n >= N</tt>.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>bitset& reset(size_t n)</tt>
</TD>
<TD VAlign=top>
Clears bit <tt>n</tt>.
Throws <tt>out_of_range</tt> if <tt>n >= N</tt>.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>bitset flip(size_t n)</tt>
</TD>
<TD VAlign=top>
Flips bit <tt>n</tt>.
Throws <tt>out_of_range</tt> if <tt>n >= N</tt>.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>size_t size() const</tt>
</TD>
<TD VAlign=top>
Returns <tt>N</tt>.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>size_t count() const</tt>
</TD>
<TD VAlign=top>
Returns the number of bits that are set.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>bool any() const</tt>
</TD>
<TD VAlign=top>
Returns <tt>true</tt> if any bits are set.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>bool none() const</tt>
</TD>
<TD VAlign=top>
Returns <tt>true</tt> if no bits are set.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>bool test(size_t n) const</tt>
</TD>
<TD VAlign=top>
Returns <tt>true</tt> if bit <tt>n</tt> is set.
Throws <tt>out_of_range</tt> if <tt>n >= N</tt>.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>reference operator[](size_t n)</tt>
</TD>
<TD VAlign=top>
Returns a <tt>reference</tt> to bit <tt>n</tt>. Note that <tt>reference</tt> is a
proxy class with an assignment operator and a conversion to <tt>bool</tt>,
which allows you to use <tt>operator[]</tt> for assignment. That is, you
can write both <tt>x = b[n]</tt> and <tt>b[n] = x</tt>.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>bool operator[](size_t n) const</tt>
</TD>
<TD VAlign=top>
Returns <tt>true</tt> if bit <tt>n</tt> is set.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>unsigned long to_ulong() const</tt>
</TD>
<TD VAlign=top>
Returns an <tt>unsigned long</tt> corresponding to the bits in <tt>*this</tt>.
Throws <tt>overflow_error</tt> if it is impossible to represent <tt>*this</tt> as
an <tt>unsigned long</tt>. (That is, if <tt>N</tt> is larger than the number of
bits in an <tt>unsigned long</tt> and if any of the high-order bits are set.
</TD>
</TR>
<TR>
<TD VAlign=top>
<pre>
template<class Char, class Traits, class Alloc>
<A href="basic_string.html">basic_string</A><Char,Traits,Alloc> to_string() const
</pre>
</TD>
<TD VAlign=top>
Returns a string representation of <tt>*this</tt>: each character is
<tt>1</tt> if the corresponding bit is set, and <tt>0</tt> if it is not.
In general, character position <tt>i</tt> corresponds to bit position
<tt>N - 1 - i</tt>. Note that this member function relies on two
language features, <i>member templates</i> and <i>explicit function
template argument specification</i>, that are not yet universally
available; this member function is disabled for compilers that do
not support those features. Note also that the syntax for calling
this member function is somewhat cumbersome. To convert a bitset <tt>b</tt>
to an ordinary string, you must write
<pre>
b.template to_string<char, char_traits<char>, allocator<char> >()
</pre>
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>bitset operator&(const bitset&, const bitset&)</tt>
</TD>
<TD VAlign=top>
Bitwise and of two bitsets. This is a global function,
not a member function. Note that the expression <tt>b1 & b2</tt>
is equivalent to creating a temporary copy of <tt>b1</tt>, using
<tt>operator&=</tt>, and returning the temporary copy.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>bitset operator|(const bitset&, const bitset&)</tt>
</TD>
<TD VAlign=top>
Bitwise or of two bitsets. This is a global function,
not a member function. Note that the expression <tt>b1 | b2</tt>
is equivalent to creating a temporary copy of <tt>b1</tt>, using
<tt>operator|=</tt>, and returning the temporary copy.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>bitset operator^(const bitset&, const bitset&)</tt>
</TD>
<TD VAlign=top>
Bitwise exclusive or of two bitsets. This is a global function,
not a member function. Note that the expression <tt>b1 ^ b2</tt>
is equivalent to creating a temporary copy of <tt>b1</tt>, using
<tt>operator^=</tt>, and returning the temporary copy.
</TD>
</TR>
<TR>
<TD VAlign=top>
<pre>
template <class Char, class Traits,
size_t N>
basic_istream<Char, Traits>&
operator>>(basic_istream<Char,Traits>& is,
bitset<N>& x)
</pre>
</TD>
<TD VAlign=top>
Extract a <tt>bitset</tt> from an input stream. This function first
skips whitespace, then extracts up to <tt>N</tt> characters from the
input stream. It stops either when it has successfully
extracted <tt>N</tt> character, or when extraction fails, or when
it sees a character that is something other than <tt>1</tt> (in which
case it does not extract that character). It then assigns a
value to the <tt>bitset</tt> in the same way as if it were initializing
the <tt>bitset</tt> from a string. So, for example, if the input stream
contains the characters <tt>"1100abc"</tt>, it will assign the value
<tt>12ul</tt> to the <tt>bitset</tt>, and the next character read from the input
stream will be <tt>a</tt>.
</TD>
</TR>
<TR>
<TD VAlign=top>
<pre>
template <class Char, class Traits,
size_t N>
basic_ostream<Char,Traits>&
operator>>(basic_ostream<Char,Traits>& os,
const bitset<N>& x)
</pre>
</TD>
<TD VAlign=top>
Output a <tt>bitset</tt> to an output stream. This function behaves as
if it converts the <tt>bitset</tt> to a string and then writes that string
to the output stream. That is, it is equivalent to
<pre>
os << x.template to_string<Char,Traits,allocator<Char> >()
</pre>
</TD>
</tr>
</table>
<h3>Notes</h3>
<h3>See also</h3>
<tt><A href="Vector.html">vector</A></tt>, <tt><A href="bit_vector.html" tppabs="http://www.sgi.com/Technology/STL/bit_vector.shtml">bit_vector</A></tt>, <tt><A href="basic_string.html" tppabs="http://www.sgi.com/Technology/STL/basic_string.shtml">string</A></tt>
<HR SIZE="6"> <FONT SIZE="-2"> Copyright © 1996 Silicon Graphics, Inc.
<HR>
<TABLE BORDER=0 WIDTH="100%" >
<TR>
<TD WIDTH="33%"><FONT SIZE=-1><A HREF="index.html" >
STL</A></FONT></TD>
<TD WIDTH="33%">
<CENTER><FONT SIZE=-2>© Copyright 1997-1998 CodeGuru</FONT> </CENTER>
</TD>
<TD WIDTH="34%">
<DIV ALIGN=right><FONT SIZE=-1>Contact : <A HREF="mailto:webmaster@codeguru.com">webmaster@codeguru.com</A> </FONT></DIV>
</TD>
</TR>
</TABLE>
<SCRIPT LANGUAGE="JavaScript" ><!--
var adurl = "/cgi-bin/doubleclick.cgi?";
if( self.adcategory )
adurl += adcategory;
else
adurl += "mfc";
if( self.parent.norefreshad )
parent.norefreshad = false;
else if( validframes )
parent.frames['ad'].location = adurl;
if( !validframes && nfrm == -1)
{
var dclkPage = "www.codeguru.com/";
if( self.adcategory )
dclkPage += adcategory;
else
dclkPage += "mfc";
// var random = Math.random();
document.write('<nolayer><center>');
document.write('<iframe src="http://ad.doubleclick.net/adi/' + dclkPage + ';ord='
+ random + '" width=470 height=62 marginwidth=0 marginheight=0 hspace=0 vspace=0 '
+ 'frameborder=0 scrolling=no bordercolor="#000000">');
document.write('<a href="http://ad.doubleclick.net/jump/' + dclkPage + ';ord='
+ random + '">');
document.write('<img src="http://ad.doubleclick.net/ad/' + dclkPage + ';ord='
+ random + '" height=60 width=468>' + '</a>');
document.write('</iframe>');
document.write('</center></nolayer>');
document.write('<layer src="http://ad.doubleclick.net/adl/' + dclkPage +
';ord=' + random + '"></layer>');
document.write('<ilayer visibility=hide width=468 height=83></ilayer>');
}
// -->
</SCRIPT>
<!-- SCRIPT LANGUAGE="JavaScript" SRC="/global/fscript.js">
//
</SCRIPT -->
<noscript>
<p align="center">
<a href="http://ad.doubleclick.net/jump/www.codeguru.com/cpp;ord=NupacdFCY34AAHfZfDM">
<img src="http://ad.doubleclick.net/ad/www.codeguru.com/cpp;ord=NupacdFCY34AAHfZfDM"></a>
</p>
</noscript>
</BODY>
</HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -