Thread: Need help with simple data types

  1. #1
    Registered User
    Join Date
    Oct 2001

    Question Need help with simple data types

    I need help in writing a program wich outputs the size of all the simple data types along with the minimum and maximum values for each of these simple data types. Is there a way to do all of this in a short call statement in a program without writing every line to output the data?
    If not, do I have to call every simple data type?
    Please help. Thanks with any help or suggestions.

  2. #2
    of Zen Hall zen's Avatar
    Join Date
    Aug 2001
    I think you'll have to individually print each type, but you can save typing using a macro or template function -

    #include <limits>
    #include <iostream>
    using namespace std;
    template <class T>
     void TypeOutput(T a)
    	cout << "Size : " <<sizeof(T) << " Min: " 
    		<< numeric_limits<T>::min() << " Max: " << 
    		numeric_limits<T>::max() << endl;
    int main()
    	unsigned short a;
    	short b;
    	unsigned c ;
    	int d ;
    	unsigned long e;
    	long f;
    	cout << "unsigned short: "; TypeOutput(a);
    	cout << "signed short: "; TypeOutput(b);
    	cout << "unsigned int: "; TypeOutput(c);
    	cout << "signed int: "; TypeOutput(d);
    	cout << "unsigned long: "; TypeOutput(e);
    	cout << "signed long: "; TypeOutput(f);
    	return 0;

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Extending basic data types.
    By nempo in forum C++ Programming
    Replies: 23
    Last Post: 09-25-2007, 03:28 PM
  2. What are abstract data types
    By bhagwat_maimt in forum C++ Programming
    Replies: 4
    Last Post: 01-04-2007, 09:43 AM
  3. HUGE fps jump
    By DavidP in forum Game Programming
    Replies: 23
    Last Post: 07-01-2004, 10:36 AM
  4. Request for comments
    By Prelude in forum A Brief History of
    Replies: 15
    Last Post: 01-02-2004, 09:33 AM
  5. Using enumerated data types
    By SXO in forum C++ Programming
    Replies: 7
    Last Post: 09-04-2001, 06:26 PM