std::basic_istream::read
来自cppreference.com
< cpp | io | basic istream
|
|
该页由英文版wiki使用Google Translate机器翻译而来。
该翻译可能存在错误或用词不当。鼠标停留在文本上可以看到原版本。你可以帮助我们修正错误或改进翻译。参见说明请点击这里. |
| basic_istream& read( char_type* s, std::streamsize count ); |
||
提取字符流.
表现为
UnformattedInputFunction。在构造和检查岗哨对象的,提取字符,并将它们存储到连续位置的字符数组的第一个元素是指向s。字符被提取出来并保存,直到发生下列条件:原文:
Behaves as
UnformattedInputFunction. After constructing and checking the sentry object, extracts characters and stores them into successive locations of the character array whose first element is pointed to by s. Characters are extracted and stored until any of the following conditions occurs:-
count字符被提取并存储原文:countcharacters were extracted and stored
- 结束文件的情况发生在输入序列(在这种情况下,setstate(failbit|eofbit)被称为.原文:end of file condition occurs on the input sequence (in which case, setstate(failbit|eofbit) is called.
目录 |
[编辑] 参数
| s | - | 指针指向的字符数组来存储的字符
原文: pointer to the character array to store the characters to |
| count | - | 要读取的字符数
|
[编辑] 返回值
*this
[编辑] 示例
读()通常用于二进制I / O
原文:
read() is often used for binary I/O
#include <iostream> #include <string> #include <sstream> #include <cstdint> int main() { std::string bin = {'\x12', '\x12', '\x12', '\x12'}; std::istringstream raw(bin); std::uint32_t n; raw.read(reinterpret_cast<char*>(&n), 4); std::cout << std::hex << std::showbase << n << '\n'; }
输出:
0x12121212
[编辑] 另请参阅
| 插入的字符块 (公共成员函数of std::basic_ostream)
| |
| 提取物格式的数据 (公共成员函数) | |
| 提取已经可用块的字符 原文: extracts already available blocks of characters (公共成员函数) | |
| 提取字符 (公共成员函数) | |
| 提取字符,直到给定的字符被发现 原文: extracts characters until the given character is found (公共成员函数) | |
| 从文件读取 (函数) | |