Advertisement
Guest User

Untitled

a guest
Apr 4th, 2010
406
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. n cin.ignore()
  2. what if you did
  3. cin.ignore(5, '\n');
  4. and the user entered
  5.  
  6. abcdefghij
  7.  
  8. that would be over 5. But this would only ignore 5 characters
  9.  
  10. so the programmer used
  11. cin.ignore(10, '\n');
  12. and the user entered
  13. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
  14.  
  15. and it still doesn't cover what the user entered
  16.  
  17. so the programmer used
  18. cin.ignore(20,'\n');
  19. and the user entered
  20. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
  21.  
  22. still not enough
  23.  
  24. so my question is, if you never can predict what the user is going to enter,
  25. how do you even come close to picking the numeric that is needed within ignore?
  26.  
  27. ignore will work in some case and fail in other
  28. why would you pick code that could fail in some cases?
  29. not good coding?
  30.  
  31. you need code that will work exactly as you want in all cases
  32.  
  33. and that would NOT be with ignore
  34.  
  35. so what will work in all cases?
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement