2005年4月6日

ostream_iterator< int > ofile( cout, " ");

ostream_iterator
这是一个游标类,
ostream_iterator< int > ofile( cout, " ");
这个表示这是一个直接指向cout(默认打开的输出流)的游标类,两个引号中间有一个空格,我能够编译,估计是你的空格少了,这是表示流的分隔标志,也可以用其他的字符

#include
#include
#include
using namespace std;

int main(int argc, char* argv[])
{
vector v;
vector vc;
ostream_iterator< int > ofile( cout, ",");
ostream_iterator ofile2( cout,";");
for(int i=0;i<10;i++) v.push_back(i);
for(i=0;i<10;i++) vc.push_back('w');
copy(v.begin(),v.end(),ofile);
copy(vc.begin(),vc.end(),ofile2);
ofile=4;ofile2='m';
return 0;
}
看看这个程序输出什么,
0,1,2,3,4,5,6,7,8,9,
w;w;w;w;w;w;w;w;w;w;
4,m;

没有评论: