Need help with simple data types

This is a discussion on Need help with simple data types within the C++ Programming forums, part of the General Programming Boards category; I need help in writing a program wich outputs the size of all the simple data types along with the ...

  1. #1
    Registered User
    Join Date
    Oct 2001
    Posts
    15

    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
    zen
    zen is offline
    of Zen Hall zen's Avatar
    Join Date
    Aug 2001
    Posts
    1,007
    I think you'll have to individually print each type, but you can save typing using a macro or template function -

    Code:
    #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);
    	
                   //etc
    
    	return 0;
    }
    zen

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, 04:28 PM
  2. What are abstract data types
    By bhagwat_maimt in forum C++ Programming
    Replies: 4
    Last Post: 01-04-2007, 10:43 AM
  3. HUGE fps jump
    By DavidP in forum Game Programming
    Replies: 23
    Last Post: 07-01-2004, 11:36 AM
  4. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM
  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