I am trying to cin numbers into two different vectors. After I entered a series of numbers for the first vector, I ctrl-D'ed. But it didn't give me a chance to enter my second series of numbers. Anything wrong?
int main ()
{
int input;
vector<int> *ivec1=new vector<int>;
vector<int> *ivec2=new vector<int>;
cout<<"enter your first vector of numbers: "<<endl;
while (cin>>input)
(*ivec1).push_back(input);
cout<<"enter your second vector of numbers: "<<endl;
while (cin>>input)
(*ivec2).push_back(input);
if((*ivec1).size () != (*ivec2).size ())
for (vector<int>::size_type ix=0; ix!=(*ivec2).size() || ix!=(*ivec1).size (); ++ix)
{
if (ivec1[ix]==ivec2[ix])
{
if ((ix==(*ivec2).size()-1) || (ix==(*ivec1).size()-1))
cout<<"there's a prefix"<<endl;
}
else
{
cout<<"not a prefix"<<endl;
break;
}
}
delete ivec1;
ivec1=0;
delete ivec2;
ivec2=0;
return 0;
}
and the output was like this
1 2 3 4
enter your first vector of numbers:
1 2 3 4
enter your second vector of numbers:
not a prefix
sloppy9, I got it, thanks. I just want to have more practice since dynamical ones are a little bit more complicated. What are the pros and cons of dynamically allocation vectors compared to static ones?