有关容器问题
#include<iostream>#include<list>
#include<vector>
using namespace std;
int main()
{
char *sa[] = {"tianfuguo", "lijing", "liufeng", "zhaoqian", "liuyingna"};
list<char*> clst(sa, sa + 5);
vector<string> svec;
svec.assign(clst.begin(), clst.end());
for(list<char*>::iterator lit = clst.begin();
lit != clst.end(); ++lit)
cout<<*lit<<'\t';
cout<<endl;
for(vector<string>::iterator vit = svec.begin();
vit != svec.end(); ++vit)
cout<<*vit<<'\t';
cout<<endl;
return 0;
}
这段程序中为什么svec.assign(clst.begin(), clst.end());这句错了啊? 应该如何修改。
一下是错误信息
Compiling...
lianxi8cpp.cpp
D:\vc++\MSDev98\MyProjects\lianxi8cpp\lianxi8cpp.cpp(158) : error C2664: 'void __thiscallstd::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::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
Error executing cl.exe.
lianxi8cpp.obj - 1 error(s), 0 warning(s)