主题:vector容器的问题
#include <iostream>
#include <vector>
using namespace std;
void disp(vector<char>& x)
{
vector<char>::iterator p=x.begin();
for (;p!=x.end();p++)
cout<<(*p)<<endl;
}
int main()
{
char a[3][5]={"sers","wqe","fyuf"};
vector<char> b(a,a+3);
for(int i=0;i<b.size();i++)
cout<<b[i]<<endl;
disp(b);
cout<<"首结点为:"<<b.front()<<endl;
cout<<"尾结点为:"<<b.back()<<endl;
return 0;
}
这段代码为什么不对?
#include <vector>
using namespace std;
void disp(vector<char>& x)
{
vector<char>::iterator p=x.begin();
for (;p!=x.end();p++)
cout<<(*p)<<endl;
}
int main()
{
char a[3][5]={"sers","wqe","fyuf"};
vector<char> b(a,a+3);
for(int i=0;i<b.size();i++)
cout<<b[i]<<endl;
disp(b);
cout<<"首结点为:"<<b.front()<<endl;
cout<<"尾结点为:"<<b.back()<<endl;
return 0;
}
这段代码为什么不对?