Thread: data testing

  1. #1
    essence of digital xddxogm3's Avatar
    Join Date
    Sep 2003

    data testing

    Please correct me on my translation of this code.
    Is the following translation accurate?

    #include <limits> // Add this for numeric_limits
    if ( !( cin>> y ) )  {
      cin.clear(); // Clear the errors
      cin.ignore ( numeric_limits<streamsize>::max(), '\n' );
      cerr<<"Invalid input, try again: ";
    Translates to if the data inputed into y doesn't match the data type y was declared as then execute the following statements.

    A follow up question is what does the header limits do?
    Does it hold the details of the following code?
    "Hence to fight and conquer in all your battles is not supreme excellence;
    supreme excellence consists in breaking the enemy's resistance without fighting."
    Art of War Sun Tzu

  2. #2
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    1) correct
    2) limits holds a lot of information much of it as template specialisations.This is just a way of saying ignore the maximum possible number of chars from cin or up to a newline.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :-

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. brace-enclosed error
    By jdc18 in forum C++ Programming
    Replies: 53
    Last Post: 05-03-2007, 05:49 PM
  2. singly linked circular list
    By DarkDot in forum C++ Programming
    Replies: 0
    Last Post: 04-24-2007, 08:55 PM
  3. Reading a file with Courier New characters
    By Noam in forum C Programming
    Replies: 3
    Last Post: 07-07-2006, 09:29 AM
  4. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 06:49 PM
  5. Post programs
    By GaPe in forum C# Programming
    Replies: 8
    Last Post: 05-12-2002, 11:07 AM