I need to store elements of a c array of strings in a vector.
Basically I need to copy all the elements of a c array into a vector<std::string>
.
#include<vector>
#include<conio.h>
#include<iostream>
using namespace std;
int main()
{
char *a[3]={"field1","field2","field3"};
//Some code here!!!!
vector<std::string>::const_iterator it=fields.begin();
for(;it!=fields.end();it++)
{
cout<<*it++<<endl;
}
getch();
}
Could anybody help me out to store c array elements into a vector?
EDIT
this below code is dumping the core!!Pls help
int main()
{
char *a[3]={"field1","field2","field3"};
std::vector<std::string> fields(a, a + 3);
vector<std::string>::const_iterator it=fields.begin();
for(;it!=fields.end();it++)
{
cout<<*it++<<endl;
}
getch();
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…