operator>><div class="t-tr-text">(性病:: basic_istream)<div class="t-tr-dropdown"><div><div><div class="t-tr-dropdown-arrow-border"></div><div class="t-tr-dropdown-arrow"></div><div class="t-tr-dropdown-h">原文:</div><div class="t-tr-dropdown-orig">(std::basic_istream)</div><div class="t-tr-dropdown-notes">这段文字是通过 [http://translate.google.com Google Translate] 自动翻译生成的。<br/>您可以帮助我们检查、纠正翻译中的错误。详情请点击[http://en.cppreference.com/w/Cppreference:MachineTranslations 这里]。</div></div></div></div></div>
来自cppreference.com
< cpp | io | basic istream
该页由英文版wiki使用Google Translate机器翻译而来。
该翻译可能存在错误或用词不当。鼠标停留在文本上可以看到原版本。你可以帮助我们修正错误或改进翻译。参见说明请点击这里. |
template< class CharT, class Traits > basic_istream<CharT,Traits>& operator>>( basic_istream<CharT,Traits>& st, CharT& ch ); |
(1) | |
template< class CharT, class Traits> basic_istream<CharT,Traits>& operator>>( basic_istream<CharT,Traits>& st, CharT* s ); |
(2) | |
template< class CharT, class Traits, class T > basic_istream<CharT,Traits>& operator>>( basic_istream<CharT,Traits>&& st, T& value ); |
(3) | (C++11 起) |
进行字符输入操作.
1) 提取字符,并且将它存储到
2) ch
.原文:
Extracts a character and stores it to
ch
.解压缩连续的字符,并将其存储在连续位置的字符数组的第一个元素是指向
s
。提取停止,如果满足下列条件之一:原文:
Extracts successive characters and stores them at successive locations of a character array whose first element is pointed to by
s
. The extraction stops if one of the following conditions are met:- 被发现的ctype<CharT>方面所确定的一个空白字符()。不提取空白字符.原文:a whitespace character (as determined by the ctype<CharT> facet) is found. The whitespace character is not extracted.
- this->width() - 1提取字符原文:this->width() - 1 characters are extracted
-
在这两种情况下,一个附加的空字符值CharT()被存储在输出结束.
3) 原文:
In either case, an additional null character value CharT() is stored at the end of the output.
调用相应的提取运算符的输入流对象,一个右值引用(相当于st >> value).
原文:
Calls the appropriate extraction operator, given an rvalue reference to an input stream object (equivalent to st >> value).
目录 |
[编辑] 注释
版本的操作员(1-2)表现为“格式化的输入功能”。也就是说,他们构建一个
sentry
在一开始就冲了tie()'D缓冲区,如果需要,检查错误,并提取物和丢弃所有领先的空白字符,除非ios_base :: skipws标志被清除的对象。尝试输入只有当sentry
对象返回true.原文:
The (1-2) versions of the operator behave as formatted input functions. That is, they construct a
sentry
object at the beginning that flushes the tie()'d buffers if needed, checks for errors, and extracts and discards all leading whitespace characters unless the ios_base::skipws flag was cleared. The input is attempted only if the sentry
object returns true.[编辑] 参数
st | - | 输入的数据流中提取
原文: input stream to extract the data from |
ch | - | 引用到一个字符,存储所提取的字符
原文: reference to a character to store the extracted character to |
s | - | 存储所提取的字符的字符串的指针
原文: pointer to a character string to store the extracted characters to |
[编辑] 返回值
st
[编辑] 示例
#include <iostream> #include <iomanip> #include <sstream> int main() { std::string input = "n greetings"; std::istringstream stream(input); char c; const int MAX = 6; char cstr[MAX]; stream >> c >> std::setw(MAX) >> cstr; std::cout << "c = " << c << '\n' << "cstr = " << cstr << '\n'; double f; std::istringstream("1.23") >> f; // rvalue stream extraction std::cout << "f = " << f << '\n'; }
输出:
c = n cstr = greet f = 1.23
[编辑] 另请参阅
提取物格式的数据 (公共成员函数) |