std::basic_istream::getline
来自cppreference.com
< cpp | io | basic istream
该页由英文版wiki使用Google Translate机器翻译而来。
该翻译可能存在错误或用词不当。鼠标停留在文本上可以看到原版本。你可以帮助我们修正错误或改进翻译。参见说明请点击这里. |
basic_istream& getline( char_type* s, std::streamsize count ); |
(1) | |
basic_istream& getline( char_type* s, std::streamsize count, char_type delim ); |
(2) | |
提取字符流的线(相当于getline(s, count, widen(’\n’)))的,直到结束
2) 原文:
Extracts characters from stream until the end of line (equivalent to getline(s, count, widen(’\n’)))
提取字符流,直到指定的分隔符.
原文:
Extracts characters from stream until the specified delimiter.
表现为
UnformattedInputFunction
。建设和检查岗哨对象的,提取的字符*this
,并将其存储在连续位置的数组,该数组的第一个元素是指向s
,直至出现以下任何情况:(测试中显示的顺序)原文:
Behaves as
UnformattedInputFunction
. After constructing and checking the sentry object, extracts characters from *this
and stored them in successive locations of the array whose first element is pointed to by s
until any of the following occurs: (tested in the order shown)- 文件的条件的结束发生在输入序列中(在这种情况下,setstate(eofbit)被执行)原文:end of file condition occurs in the input sequence (in which case setstate(eofbit) is executed)
- 下一个可用的字符
c
是分隔符,确定Traits::eq(c, delim)。分隔符中提取(不像basic_istream::get())和计入gcount()
,但还没有存储.原文:the next available characterc
is the delimiter, as determined by Traits::eq(c, delim). The delimiter is extracted (unlike basic_istream::get()) and counted towardsgcount()
, but is not stored.
- count-1字符已被提取的(在这种情况下setstate(failbit)执行).原文:count-1 characters have been extracted (in which case setstate(failbit) is executed).
如果函数中提取任何字符(例如,如果count < 1),setstate(failbit)执行.
原文:
If the function extracts no characters (e.g. if count < 1), setstate(failbit) is executed.
在任何情况下,如果
count>0
,然后将其存储到下一个连续的阵列的位置和更新的一个空字符CharT()
gcount()
.原文:
In any case, if
count>0
, it then stores a null character CharT()
into the next successive location of the array and updates gcount()
.目录 |
[编辑] 注释
由于条件#2之前测试条件#3中,输入线完全适合的缓冲液,不触发failbit.
原文:
Because condition #2 is tested before condition #3, the input line that exactly fits the buffer, does not trigger failbit.
因为终止字符算作提取的字符,输入空行不触发failbit.....
原文:
Because the terminating character is counted as extracted character, empty input line does not trigger failbit.
[编辑] 参数
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 extracted but not stored. |
[编辑] 返回值
*this
[编辑] 示例
#include <iostream> #include <sstream> #include <vector> #include <array> int main() { std::istringstream input("abc|def|gh"); std::vector<std::array<char, 4>> v; for(std::array<char, 4> a; input.getline(&a[0], 4, '|'); ) { v.push_back(a); } for(auto& a : v) { std::cout << &a[0] << '\n'; } }
输出:
abc def gh
[编辑] 另请参阅
读取数据的I / O流成一个字符串 原文: read data from an I/O stream into a string (函数) | |
提取物格式的数据 (公共成员函数) | |
提取字符 (公共成员函数) | |
提取的字符块 (公共成员函数) |