求教容器的问题
题目:将一个list容器的所有元素赋值给一个vector容器,其中list容器存储char*,vector存储string。不知道是什么错误请大家帮帮忙,谢谢。
#include<iostream>
#include <vector>
#include <string>
#include<list>
#include <deque>
using namespace std;
int main()
{
char* sa[]={"sunhang","zhangchunhua","tanbin","huangwei"};
list<char*> slst(sa,sa+4);
vector<string> svec;
svec.assign(slst.begin(),slst.end());
for (list<char*>::iterator lit=slst.begin();lit!=slst.end();lit++)
{
cout<<*lit<<" ";
}
cout<<endl;
for (vector<string>::iterator vit=svec.begin();vit!=svec.end();vit++)
{
cout<<*vit<<" ";
}
cout<<endl;
return 0;
}
Compiling...
9.cpp
D:\C++程序\9.cpp(283) : 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<char>,class std::allo
cator<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 *> >::const_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.obj - 1 error(s), 0 warning(s)
不知道是什么错误请大家帮帮忙,谢谢。