operator<<,>>(std::bitset)
来自cppreference.com
|
|
该页由英文版wiki使用Google Translate机器翻译而来。
该翻译可能存在错误或用词不当。鼠标停留在文本上可以看到原版本。你可以帮助我们修正错误或改进翻译。参见说明请点击这里. |
| template <class CharT, class Traits, size_t N> std::basic_ostream<CharT, Traits>& operator<<(std::basic_ostream<CharT, Traits>& os, |
(1) | |
| template <class CharT, class Traits, size_t N> std::basic_istream<CharT, Traits>& operator>>(std::basic_istream<CharT, Traits>& is, |
(2) | |
插入或从字符流中提取一个bitset.
1) 原文:
Inserts or extracts a bitset from a character stream.
写入字符流
2) xbitset的os.原文:
Writes the bitset
x to the character stream os.提取物从
N并存储is字符的字符在bitset的x.原文:
Extracts up to
N characters from is and stores the characters in the bitset x.字符,直到提取
原文:
Characters are extracted until either
-
N字符已被读取, - 文件结束发生在
is,或 - 下一个字符既不是
is.widen('0')也不is.widen('1').原文:the next character is neitheris.widen('0')noris.widen('1').
如果没有字符被提取,
is.setstate(ios_base::failbit)被称为.原文:
If no characters are extracted,
is.setstate(ios_base::failbit) is called.目录 |
[编辑] 参数
| os | - | 写入字符流
|
| is | - | 读取的字符流
|
| x | - | 的bitset的读或写
|
[编辑] 返回值
字符流,例如操作
os或is.原文:
The character stream that was operated on, e.g.
os or is.[编辑] 示例
#include <bitset> #include <iostream> #include <sstream> int main() { std::string bit_string = "001101"; std::istringstream bit_stream(bit_string); std::bitset<3> b1; bit_stream >> b1; std::cout << b1 << '\n'; std::bitset<8> b2; bit_stream >> b2; std::cout << b2 << '\n'; }
输出:
001 00000101
[编辑] 另请参阅
| 执行二进制左移和右移 原文: performs binary shift left and shift right (公共成员函数) | |