View Single Post
Old 11-23-2004, 06:55 PM   #6 (permalink)
Pragma
I am Winter Born
 
Pragma's Avatar
 
Location: Alexandria, VA
So the way I read it, your problem is that you're expecting someone to input a string containing nothing but numbers. If the string contains other symbols, things start messing up.

This is pretty much predicable (and expected) behaviour. The problem you're running into is that when you pass the >> operator an Integer variable, if it doesn't have an integer, it won't move past that spot in the input stream. This is so that another >> operator can read the value into another type of variable.

A better idea would be to read the entire line into a string, then use some kind of string tokenizer or regular expression to break it apart by spaces. Then, you can read each value into your array if it's an integer - if not, ignore it and continue.
Pragma is offline  
 

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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62