error C2664: 'push_back' : cannot convert parameter 1 from 'class std::basic_string<char,struct std:
#include<iostream>#include<vector>#include<string>usingnamespacestd;intmain(){vector<...
#include<iostream>
#include<vector>
#include<string>
using namespace std;
int main()
{
vector<int> svec;
string str;
cout<<"请输入字符串"<<endl;
while(cin>>str)
svec.push_back(str);
char **parr=new char*[svec.size()];
size_t ix=0;
for(vector<string>::iterator iter=svec.begin();iter!=svec.end();++iter,++ix)
{char *p=new char[(*iter).size()+1];
strcpy(p,(*iter).c_str());
parr[ix]=p;
}
cout<<"容器的组成"<<endl;
for(vector<string>::iterator iter2=svec.begin();iter2!=svec.end();++iter2)
cout<<*iter2<<endl;
cout<<"数组的组成"<<endl;
for(ix=0;ix!=svec.size();++ix)
cout<<parr[ix]<<endl;
for(ix=0;ix!=svec.size();++ix)
delete [] parr;
return 0;}
哪错了 求指点 展开
#include<vector>
#include<string>
using namespace std;
int main()
{
vector<int> svec;
string str;
cout<<"请输入字符串"<<endl;
while(cin>>str)
svec.push_back(str);
char **parr=new char*[svec.size()];
size_t ix=0;
for(vector<string>::iterator iter=svec.begin();iter!=svec.end();++iter,++ix)
{char *p=new char[(*iter).size()+1];
strcpy(p,(*iter).c_str());
parr[ix]=p;
}
cout<<"容器的组成"<<endl;
for(vector<string>::iterator iter2=svec.begin();iter2!=svec.end();++iter2)
cout<<*iter2<<endl;
cout<<"数组的组成"<<endl;
for(ix=0;ix!=svec.size();++ix)
cout<<parr[ix]<<endl;
for(ix=0;ix!=svec.size();++ix)
delete [] parr;
return 0;}
哪错了 求指点 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询