如何实现list容器向vector容器的覆值
#include<iostream>#include<list>#include<vector>#include<string>usingnamespacestd;int...
#include <iostream>
#include <list>
#include <vector>
#include <string>
using namespace std;
int main()
{
list<char> slist;
slist.push_back('a');
slist.push_back('b');
slist.push_back('c');
vector<char> vect(slist.begin(),slist.end());
vector<char>::iterator iter = vect.begin();
while(iter != vect.end())
{
cout<<*iter++<<endl;
}
return 0;
}
报错.用insert也报错.但是,如果用string类型的话,用这个,就不会报错.
那如果想用list-->vector .或是调过来,要如何处理啊??
错误提示:
--------------------Configuration: Test - Win32 Debug--------------------
Compiling...
Test.cpp
d:\c\c++\test\test.cpp(16) : error C2664: '__thiscall std::vector<char,class std::allocator<char> >::std::vector<char,class std::allocator<char> >(unsigned int,const char &,const class std::allocator<char> &)' : cannot convert parameter 1 from 'clas
s std::list<char,class std::allocator<char> >::iterator' to 'unsigned int'
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
执行 cl.exe 时出错.
Creating browse info file...
Test.exe - 1 error(s), 0 warning(s)
是不是编译器的事啊?
请问你用的什么编译
我是VC++6.0 展开
#include <list>
#include <vector>
#include <string>
using namespace std;
int main()
{
list<char> slist;
slist.push_back('a');
slist.push_back('b');
slist.push_back('c');
vector<char> vect(slist.begin(),slist.end());
vector<char>::iterator iter = vect.begin();
while(iter != vect.end())
{
cout<<*iter++<<endl;
}
return 0;
}
报错.用insert也报错.但是,如果用string类型的话,用这个,就不会报错.
那如果想用list-->vector .或是调过来,要如何处理啊??
错误提示:
--------------------Configuration: Test - Win32 Debug--------------------
Compiling...
Test.cpp
d:\c\c++\test\test.cpp(16) : error C2664: '__thiscall std::vector<char,class std::allocator<char> >::std::vector<char,class std::allocator<char> >(unsigned int,const char &,const class std::allocator<char> &)' : cannot convert parameter 1 from 'clas
s std::list<char,class std::allocator<char> >::iterator' to 'unsigned int'
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
执行 cl.exe 时出错.
Creating browse info file...
Test.exe - 1 error(s), 0 warning(s)
是不是编译器的事啊?
请问你用的什么编译
我是VC++6.0 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询