data testing

This is a discussion on data testing within the C++ Programming forums, part of the General Programming Boards category; Please correct me on my translation of this code. Is the following translation accurate? Code: #include <limits> // Add this ...

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

    data testing

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

    Code:
     
    #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?
    Code:
    numeric_limits<streamsize>::max()
    "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
    Posts
    2,572
    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 :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

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, 06:49 PM
  2. singly linked circular list
    By DarkDot in forum C++ Programming
    Replies: 0
    Last Post: 04-24-2007, 09:55 PM
  3. Reading a file with Courier New characters
    By Noam in forum C Programming
    Replies: 3
    Last Post: 07-07-2006, 10:29 AM
  4. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 07:49 PM
  5. Post programs
    By GaPe in forum C# Programming
    Replies: 8
    Last Post: 05-12-2002, 12:07 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21