cin to two vectors

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?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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
closed account (DSLq5Di1)
I imagine ctrl-d would set the end-of-file state on cin, you'll need to clear() it before proceeding with your second while loop.

Is there any paticular reason to allocate the vectors dynamically?
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?
ihm wrote:
What are the pros and cons of dynamically allocation vectors compared to static ones?

Never dynamically allocate if you can avoid it. It is a source of memory leaks and segmentation faults.
Topic archived. No new replies allowed.