std::basic_istream::get
来自cppreference.com
< cpp | io | basic istream
该页由英文版wiki使用Google Translate机器翻译而来。
该翻译可能存在错误或用词不当。鼠标停留在文本上可以看到原版本。你可以帮助我们修正错误或改进翻译。参见说明请点击这里. |
int_type get(); |
(1) | |
basic_istream& get( char_type& ch ); |
(2) | |
basic_istream& get( char_type* s, std::streamsize count ); |
(3) | |
basic_istream& get( char_type* s, std::streamsize count, char_type delim ); |
(4) | |
basic_istream& get( basic_streambuf& strbuf ); |
(5) | |
basic_istream& get( basic_streambuf& strbuf, char_type delim ); |
(6) | |
提取字符或字符流.
原文:
Extracts character or characters from stream.
所有版本的行为为
1) UnformattedInputFunction
s。在构造和检查岗哨对象的,这些函数执行以下操作:原文:
All versions behave as
UnformattedInputFunction
s. After constructing and checking the sentry object, these functions perform the following:读取一个字符,如果有返回。否则,返回Traits::eof()和的套
2) failbit
,eofbit
.原文:
reads one character and returns it if available. Otherwise, returns Traits::eof() and sets
failbit
and eofbit
.读出一个字符,并且将它存储到
3) ch
如果可用。否则,叶ch
不变并设置failbit
eofbit
。请注意,此功能不超载signed char和unsigned char的类型,不同的格式化字符输入操作符>>.原文:
reads one character and stores it to
ch
if available. Otherwise, leaves ch
unmodified and sets failbit
and eofbit
. Note that this function is not overloaded on the types signed char and unsigned char, unlike the formatted character input operator>>.get(s, count, widen('\n'))相同,即,读取至多count-1字符,并将它们存储到字符串所指向
4) s
直到'\n'发现.原文:
same as get(s, count, widen('\n')), that is, reads at most count-1 characters and stores them into character string pointed to by
s
until '\n' is found.读取字符,并将它们存储到连续位置的字符数组的第一个元素是指向
s
。字符提取和存储,直至出现以下任何情况原文:
reads characters and stores them into the successive locations of the character array whose first element is pointed to by
s
. Characters are extracted and stored until any of the following occurs:- n-1个的字符已经被存储
- 结束文件的情况发生在输入序列(setstate(eofbit)被调用)原文:end of file condition occurs in the input sequence (setstate(eofbit) is called)
- 下一个可用的输入字符
c
等于delim
,由Traits::eq(c, delim)。这个字是没有提取(不像basic_istream::getline())原文:the next available input characterc
equalsdelim
, as determined by Traits::eq(c, delim). This character is not extracted (unlike basic_istream::getline())
如果没有字符提取,调用setstate(failbit)。在任何情况下,如果
5) count>0
阵列连续的下一个位置,被存储在一个空字符(CharT().原文:
If no characters were extracted, calls setstate(failbit). In any case, if
count>0
, a null character (CharT() is stored in the next successive location of the array.相同get(strbuf, widen('\n')),即,读取可用字符,并将它们插入到给定的basic_streambuf对象,直到'\n'发现.
6) 原文:
same as get(strbuf, widen('\n')), that is, reads available characters and inserts them to the given basic_streambuf object until '\n' is found.
读取字符,并将它们插入到由给定的basic_streambuf对象控制的输出序列的字符被提取和插入
strbuf
直到任何会发生以下情况:原文:
reads characters and inserts them to the output sequence controlled by the given basic_streambuf object. Characters are extracted and inserted into
strbuf
until any of the following occurs:- 结束文件的条件发生在输入序列中原文:end of file condition occurs in the input sequence
- 插入输出顺序发生故障时(在这种情况下,不能被插入的字符,还没有提取)原文:insert into the output sequence fails (in which case the character that could not be inserted, is not extracted)
- 的下一个可用的输入字符
c
等于delim
,所确定的Traits::eq(c, delim)该字还没有提取.原文:the next available input characterc
equalsdelim
, as determined by Traits::eq(c, delim). This character is not extracted.
- 发生异常(在这种情况下,异常被捕获并重新抛出)原文:an exception occurs (in which case the exception is caught and not rethrown)
如果没有字符提取,呼叫setstate(failbit).
原文:
If no characters were extracted, calls setstate(failbit).
所有版本
gcount()
提取的字符的数目设置的值.原文:
All versions set the value of
gcount()
to the number of characters extracted.目录 |
[编辑] 参数
ch | - | 引用的字符写的结果
原文: reference to the character to write the result to |
s | - | 指针的存储的字符的字符串
原文: pointer to the character string to store the characters to |
count | - | 所指向的字符串的大小
s 原文: size of character string pointed to by s |
delim | - | 分隔符,停止提取的。还没有提取的,而不是存储.
原文: delimiting character to stop the extraction at. It is not extracted and not stored. |
strbuf | - | 流缓冲区读取的内容
原文: stream buffer to read the content to |
[编辑] 返回值
1)所提取的字符或Traits::eof()
原文:
the extracted character or Traits::eof()
2-6) *this
[编辑] 示例
#include <sstream> #include <iostream> int main() { std::istringstream s1("Hello, world."); char c1 = s1.get(); // reads 'H' std::cout << "after reading " << c1 << ", gcount() == " << s1.gcount() << '\n'; char c2; s1.get(c2); // reads 'e' char str[5]; s1.get(str, 5); // reads "llo," std::cout << "after reading " << str << ", gcount() == " << s1.gcount() << '\n'; std::cout << c1 << c2 << str; s1.get(*std::cout.rdbuf()); // reads the rest, not including '\n' std::cout << "\nAfter the last get(), gcount() == " << s1.gcount() << '\n'; }
输出:
after reading H, gcount() == 1 after reading llo,, gcount() == 4 Hello, world. After the last get(), gcount() == 7
[编辑] 另请参阅
提取的字符块 (公共成员函数) | |
提取物格式的数据 (公共成员函数) | |
提取字符和字符数组 原文: extracts characters and character arrays (函数模板) |