接受一个&istream参数,打印在标准输出上

来源:互联网 发布:net编程语言 编辑:程序博客网 时间:2024/06/05 17:35
此函数从给定流中读取数据, 直至遇到文件结束标识时停止, 他将读取的数据打印在标准输出上, 完成这些之后, 在返回流之前对其进行复位, 使其处于有效状态.
<span style="font-family:Courier New;font-size:14px;">istream& ReadWordsFromConsole (istream & input){   string   word;   <vector> words;    while (input >> word || !input.eofbit) {       if(input.bad ())          cout << ("IO stream corrupted");       if(input.fail ()) {          cerr << "Data failed try again" << endl;          input.clear(istream::goodbit);         continue;       }      words.push_back (word);    }</span>
<span style="font-family:Courier New;font-size:14px;">    copy(words.cbegin(), words.cend(), </span>
<span style="font-family:Courier New;font-size:14px;"><span style="white-space:pre"></span>ostream_iterator<string>(cout, "\n"));</span>
<span style="font-family:Courier New;font-size:14px;">    input.clear();    returninput;}</span>


0 0