|
-
October 29th, 2003, 08:49 PM
#1
simple console i/o question
Given these requirements for a console application:
Enter a series of integers seperated by whitespace. The first integer represents the quantity of integers to follow.
Ex. 3 5 18 21
or. 5 17 -46 3 198 2
I have been attempting the following to read the integers and store them in a vector:
scanf("%d", &cnt);
for(int i = 1; i <= cnt + 1; i++)
{
scanf("%d", &n);
aInts.push_back(n);
}
This works fine, unless someone enters fewer integers than the initial integer indicates. (ex. 3 19 5)
How can I test to see if the end of the input stream has been reached?
I have attempted the same type of logic using cin, to no avail.
Thank you in advance for your help.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|