Stack of istreams

This is a discussion on Stack of istreams within the C++ Programming forums, part of the General Programming Boards category; GAH! this is giving me gray hairs. how the jeef do i write a class for a stack of type ...

  1. #1
    edk
    edk is offline
    Registered User
    Join Date
    Sep 2001
    Posts
    20

    Angry Stack of istreams

    GAH! this is giving me gray hairs. how the jeef do i write a class for a stack of type istream? i don't need a template, since this is only to be used for istream.

    here's the basic stuff i have written so far:
    Code:
    #ifndef _ISSTACK_H
    #define _ISSTACK_H
    
    #include <iostream.h>
    #include <fstream.h>
    
    class ISStack{
    	private:
    		int count_, size_;
    		istream **stack_;
    	public:
    		ISStack();
    		ISStack(const ISStack &);
    		~ISStack();
    		void push(istream *);
    		istream* pop();
    		void increaseSize();
    };
    
    #endif;
    count_ = the amount of stuff in the array
    size_ = maximum amount of stuff in the array
    istream ** stack_ = the array of pointers to istreams

    i have a copy constructor so i can pass this array of pointers by value, if necessary. i have a destructor because it's a dynamic data structure that needs to be deallocated when i'm finished with it. as this stands, ISStack(), ISStack(const ISStack &), ~ISStack, void push(istream *), and void increaseSize() work. it's the pop() that i'm having a trouble with.

    is there anyone on this board who has written a class for istream stacks, or knows where i can get a nice and simple one? hell, even a plain-old stack class is fine, as long as it is VERY EASILY modifiable to support istreams and can compile using g++ 2.95.

    thanks in advance
    edk
    liberate tutamet ex inferis

  2. #2
    Registered User
    Join Date
    Sep 2001
    Posts
    2
    Hmm, is there any particular reason you can't use the standard C++ stack template? I'm pretty sure it would save you a lot of trouble. Just include the 'stack' header. Check a reference for usage, or just read through the header file itself. It's pretty easy to use. (g++ 2.95.x has this header, btw.)

  3. #3
    Registered User kitten's Avatar
    Join Date
    Aug 2001
    Posts
    109
    I'd recommend using STL containers like vector, deque, map, and so on... They're very effective and modificable.

    Ex:
    vector<WhatEverClass*> V1;
    V1.push_back(&object);

    ...and so on... see your help files.
    Making error is human, but for messing things thoroughly it takes a computer

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. stack and pointer problem
    By ramaadhitia in forum C Programming
    Replies: 2
    Last Post: 09-12-2006, 12:41 AM
  2. Question about a stack using array of pointers
    By Ricochet in forum C++ Programming
    Replies: 6
    Last Post: 11-17-2003, 10:12 PM
  3. error trying to compile stack program
    By KristTlove in forum C++ Programming
    Replies: 2
    Last Post: 11-03-2003, 06:27 PM
  4. What am I doing wrong, stack?
    By TeenyTig in forum C Programming
    Replies: 2
    Last Post: 05-27-2002, 03:12 PM
  5. Stack Program Here
    By Troll_King in forum C Programming
    Replies: 7
    Last Post: 10-15-2001, 06:36 PM

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