linuxでc++入出力反復器を練習する
1915 ワード
iterator.cpp
print.h
結果:
/*
: ,
: ,
:
: --
: --、+n、-n、
*/
#include<iterator>
#include<iostream>
using namespace std;
#include<algorithm>
#include<vector>
#include "print.h"
#include<fstream>
int main()
{
//
istream_iterator<int> in(cin);// cin,
istream_iterator<int> end;
vector<int> vi;
copy(in,end,back_inserter(vi));// , ctrl+D
print(vi.begin(),vi.end());
//
ofstream fo("out.txt");
ostream_iterator<int> o(cout,",");
ostream_iterator<int> ofile(fo," ");
copy(vi.begin(),vi.end(),o);
copy(vi.begin(),vi.end(),ofile);
fo.close();
cout<<endl;
}
print.h
//print.h
#include <iostream>
using namespace std;
#ifndef print_fun
#define print_fun
template<typename T>
///
void print(T b,T e,char c=' ')
{
bool isExit=false;
while (b!=e)
{
cout<<*b++<<c;
isExit=true;
}
if(isExit) cout<<endl;
}
template<typename K,typename V>
ostream& operator<<(ostream& o,const pair<K,V>& p)// map
{
return o<<p.first<<':'<<p.second;
}
#endif
結果: