C++迭代器问题

//inserts.cpp--copy()andinsertiterators#include<iostream>#include<string>#include<ite... //inserts.cpp--copy()and insert iterators
#include<iostream>
#include<string>
#include<iterator>
#include<vector>

int main()
{
using namespace std;
string s1[4]={"fine","fish","fashion","fate"};
string s2[2]={"busy","bats"};
string s3[2]={"silly","singers"};
vector<string> words(4);
copy(s1,s1+4,words.begin());
ostream_iterator<string,char> out(cout," ");
copy(words.begin(),words.end(),cout);
cout<<endl;
//construct anonymous back_insert_iterator object
copy(s2,s2+2,back_insert_iterator<vector<string>>(words));
copy(words.begin(),words.end(),out);
cout<<endl;

//construct anonymous insert_iterator object
copy(s3,s3+2,insert_iterator<vector<string>>(words,words.begin()));
copy(words.begin(),words.end(),out);
cout<<endl;

system("pause");
return 0;
}
vc6.0报错:
error C2061: syntax error : identifier 'words'
fatal error C1004: unexpected end of file found
求指教。
展开
 我来答
心中风情4
2013-08-31 · TA获得超过2247个赞
知道大有可为答主
回答量:1779
采纳率:66%
帮助的人:1079万
展开全部

看下面说明:

#include<iostream>
#include<string>
#include<iterator>
#include<vector>
using namespace std;

int main()
{
string s1[4]={"fine","fish","fashion","fate"};
string s2[2]={"busy","bats"};
string s3[2]={"silly","singers"};
vector<string> words(4);
copy(s1,s1+4,words.begin());
ostream_iterator<string,char> out(cout," ");
copy(words.begin(),words.end(),out);//这里应该是用out,不是cout
cout<<endl;
//construct anonymous back_insert_iterator object
copy(s2,s2+2,back_insert_iterator<vector<string> >(words)); //两个>间需要一个空格
copy(words.begin(),words.end(),out);
cout<<endl;

//construct anonymous insert_iterator object
copy(s3,s3+2,insert_iterator<vector<string> >(words,words.begin()));//两个>间需要一个空格
copy(words.begin(),words.end(),out);
cout<<endl;

system("pause");
return 0;
}
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式