流迭代器的應用

2021-06-09 14:48:44 字數 467 閱讀 9091

使用istream_iterator物件從標準輸入讀一些列的整數,使用ostream—iterator物件將其中的奇數寫入到乙個檔案中,並在給個寫入的值後面加上乙個空格,同時用另乙個ostream—iterator物件將偶數寫到第二個檔案中,每個寫入的值都存放單獨的行中。

#include#include#include#include#include#include#include#include#include#include#include#include#include#define n 1005

using namespace std;

bool cmp(const int& a,const int& b)

void display(const int& a)

file.close();

file1.close();

return 0;

}

流迭代器的使用

10.29 編寫程式,使用流迭代器讀取乙個文字檔案,存入乙個vector中的string裡。include include include include include using namespace std intmain 10.30 使用流迭代器 sort和copy從標準輸入讀取乙個整數序列,...

io流迭代器

建立乙個流迭代器的時候必須指定迭代器將要讀寫的物件型別。istream iterator istream iteratorin iter cin 從cin讀取int istream iteratoreof 尾後迭代器通過流迭代器讀入資料的例子 while in iter eof 注意 運算子的優先順...

C STL 流迭代器

流迭代器是一種迭代器介面卡。istream iterator用於讀取輸入流,ostream iterator用於寫輸出流。這些迭代器將它們所對應的流視為特定型別的元素序列。使用流迭代器時,可以用泛型演算法從流物件中讀資料或將資料寫入到流物件中。流迭代器的建構函式如下 流迭代器的基本操作如下 1 流迭...