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
求指教。 展开
#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
求指教。 展开
1个回答
展开全部
看下面说明:
#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;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询