Thread: Stack of istreams

  1. #1
    Registered User
    Join Date
    Sep 2001

    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:
    #ifndef _ISSTACK_H
    #define _ISSTACK_H
    #include <iostream.h>
    #include <fstream.h>
    class ISStack{
    		int count_, size_;
    		istream **stack_;
    		ISStack(const ISStack &);
    		void push(istream *);
    		istream* pop();
    		void increaseSize();
    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
    liberate tutamet ex inferis

  2. #2
    Registered User
    Join Date
    Sep 2001
    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
    I'd recommend using STL containers like vector, deque, map, and so on... They're very effective and modificable.

    vector<WhatEverClass*> V1;

    ...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-11-2006, 11:41 PM
  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, 02:12 PM
  5. Stack Program Here
    By Troll_King in forum C Programming
    Replies: 7
    Last Post: 10-15-2001, 05:36 PM