容器赋值问题.
#include<iostream>#include<string>
#include<vector>
#include<list>
using namespace std;
int main()
{
char *sa[]={"I","love","you","!"};
list< char* > slist(sa,sa+4);
vector< string > svec;
//string str;
//将list对象的所有元素赋值给vector对象
svec.assign(slist.begin(),slist.end());
for(list< char* >::iterator ix=slist.begin();ix!=slist.end();++ix)
cout<<*ix<<'\t';
cout<<endl;
for(vector< string >::iterator it=svec.begin();it!=svec.end();++it)
cout<<*it<<'\t';
cout<<endl;
return 0;
}
执行后:
-Configuration: 容器9-28 - Win32 Debug--------------------
Compiling...
容器9-28.cpp
F:\C语言加深\C++\cprimer\容器9-28.cpp(13) : error C2664: 'void __thiscall std::vector<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::allocator<class std::basic_string<char,struct std::char_traits<c
har>,class std::allocator<char> > > >::assign(const class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > *,const class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > *)' : cannot
convert parameter 1 from 'class std::list<char *,class std::allocator<char *> >::iterator' to 'const class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > *'
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
执行 cl.exe 时出错.
容器9-28.obj - 1 error(s), 0 warning(s)
想问下,是那里的问题.