C++ Checking Data Types

This is a discussion on C++ Checking Data Types within the C++ Programming forums, part of the General Programming Boards category; When I input an integer value using cin >> , how can I implement error-checking to make sure an integer ...

  1. #1
    G Fresh
    Guest

    Smile C++ Checking Data Types

    When I input an integer value using cin >> , how can I implement error-checking to make sure an integer was entered?

  2. #2
    Registered User Liam Battle's Avatar
    Join Date
    Jan 2002
    Posts
    114
    Well easy, just use the ctype.h

    You can use isdigit() or isalpha() function

    I also have the feeling you want to know how to check the size of the datatype that was used, you can use the sizeof keyword to do that...

    ie: a = sizeof b;

    those two things should help ya out
    Last edited by Liam Battle; 04-28-2002 at 11:47 PM.

  3. #3
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,136
    Search the board, it has come up before. Look up cin.good(), cin.bad(), cin.fail().

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. What are abstract data types
    By bhagwat_maimt in forum C++ Programming
    Replies: 4
    Last Post: 01-04-2007, 10:43 AM
  2. Errors
    By Rhidian in forum C Programming
    Replies: 10
    Last Post: 04-04-2005, 01:22 PM
  3. Very angry: "two or more data types in declaration"
    By quzah in forum C Programming
    Replies: 2
    Last Post: 06-04-2003, 08:16 AM
  4. C Programming Question
    By TK in forum A Brief History of Cprogramming.com
    Replies: 13
    Last Post: 07-04-2002, 08:11 PM
  5. Using enumerated data types
    By SXO in forum C++ Programming
    Replies: 7
    Last Post: 09-04-2001, 07:26 PM

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