Thread: Just trying to cout an empty set

  1. #1
    Registered User
    Join Date
    Feb 2005
    Posts
    17

    Just trying to cout an empty set

    Can someone explain to me how to cout an empty set from this code? I know that the second idx should reference the array but don't know how to do it.

    main.cpp
    Code:
    int main()
    {
    	IntegerSet a;
    
    	cout << "Empty Set" << endl;
    	a.printSet();
    	getch();
    }

    IntegerSet.cpp
    Code:
    void IntegerSet::printSet()
    {
    	for( int idx = 1; idx <= arraySize; ++idx )
    		cout << idx << ")" << setw( 3 ) << idx << endl;
    }
    IntegerSet.h
    Code:
    #ifndef INTEGERSET_H
    #define INTEGERSET_H
    
    const int arraySize = 100;
    
    class IntegerSet 
    {
    public:
    void printSet();
    
    private:
    	int array;
    
    };
    
    #endif

  2. #2
    ^ Read Backwards^
    Join Date
    Sep 2005
    Location
    Earth
    Posts
    282
    I do not see an array anywhere in the code you posted?
    But if you did have an array, you would 'cout << array_name[idx]' in your for loop (is one method).

  3. #3
    semi-colon generator ChaosEngine's Avatar
    Join Date
    Sep 2005
    Location
    Chch, NZ
    Posts
    597
    Quote Originally Posted by Enahs
    I do not see an array anywhere in the code you posted?
    But if you did have an array, you would 'cout << array_name[idx]' in your for loop (is one method).
    and make sure it's zero counted i.e. change your code
    Code:
    for( int idx = 1; idx <= arraySize; ++idx )
    to
    Code:
    for( int idx = 0; idx < arraySize; ++idx )
    "I saw a sign that said 'Drink Canada Dry', so I started"
    -- Brendan Behan

    Free Compiler: Visual C++ 2005 Express
    If you program in C++, you need Boost. You should also know how to use the Standard Library (STL). Want to make games? After reading this, I don't like WxWidgets anymore. Want to add some scripting to your App?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. New, making a survey program
    By shaffer in forum C++ Programming
    Replies: 18
    Last Post: 12-01-2006, 11:36 AM
  2. C help for network animator
    By fastshadow in forum Tech Board
    Replies: 7
    Last Post: 03-17-2006, 03:44 AM
  3. is my loop badly set up?
    By mabufo in forum C++ Programming
    Replies: 3
    Last Post: 02-19-2006, 03:40 PM
  4. Find all possible subset of a given set
    By Downnin in forum C++ Programming
    Replies: 7
    Last Post: 11-09-2005, 02:03 PM