How to know when the user is done entering numbers in the istream???

Dec 15, 2009 at 1:37am
Ok. In my linked list class I am making an istream operator so a user can just cin >> aList;

Here is what I have so far
1
2
3
4
5
6
7
8
9
10
11
12
istream& operator >> (istream& is, List& aList)
{
	int num;
	cout << "Current elements on List: " << aList.get_count() << endl;
	cout << "Enter a number to add to list: ";
	is >> num;
	aList.Add_To_Back(num);
.
.
.
.
.


my issue is i know i will need a while loop that will check for some input. But how am i supposed to know when they are done?? I want to give them an option say press "something" to stop entering numbers. The problem is that they can enter any number so it cant be a number. it needs to be something like press escape to stop entering numbers, but i dont know what that while statement would looklike.

Any help would be greatly appreciated.

Thanks
Brandon
Dec 15, 2009 at 1:51am
1
2
if (!(is >> num))
    //done 

If the user enters something that isn't a number, the test fails.
The user still has to press the enter key.
Dec 15, 2009 at 5:57am
You my friend are amazing. and are an ispiration to all of us.
Topic archived. No new replies allowed.