Input Problem

This is a discussion on Input Problem within the C++ Programming forums, part of the General Programming Boards category; I have written a Input function and I call it in my client file but when I build it I ...

  1. #1
    Registered User
    Join Date
    Aug 2001
    Posts
    84

    Input Problem

    I have written a Input function and I call it in my client file but when I build it I get a unresolved external error. I can't understand why I am getting this error?

    This is the input functon: void Input(ifstream& fin, ofstream& fout);


    #include<fstream.h>


    struct node;

    typedef node *Nodeptr;

    struct node
    {
    int key_value;
    node *left;
    node *right;
    //node *leaf;
    };

    //template<class Type>
    class btree
    {
    public:
    btree();
    ~btree();
    void insert(int key);
    void InOrderTranverse();
    void preOrderTranverse();
    void PostOrderTranverse();
    void destroy_tree();
    void Input(ifstream& fin, ofstream& fout);
    //void LevelOrder();
    void Output(const char prompt[]);

    node *search(int key);


    private:
    void insert(int key, node *leaf);
    void InOrderTranverse(node *leaf);
    void preOrderTranverse(node *leaf);
    void PostOrderTranverse(node *leaf);
    void destroy_tree(node *leaf);
    //void LevelOrder(node *leaf);
    node *search(int key, node *leaf);


    node *root;

    };

    /* template <class QueueItem> class Queue {
    private:
    QueueItem buffer[100];
    int head, tail, count;
    public:
    Queue();
    void Insert(QueueItem item);
    QueueItem Remove();
    int Size();
    ~Queue();
    };

    implementation

    #include"BSTTreeAndyJackson.h"
    #include<iostream>
    #include<fstream.h>

    ifstream fin;
    ofstream fout;

    //Note: This is not the complete Implementation file but just the finction
    void Input(ifstream& fin, ofstream& fout)
    {
    int num=0;
    char chr;
    fin.open("input.txt");
    fout.open("output1.txt");
    fin>>num;
    fin>>chr;

    }

    #include<iostream>
    #include<fstream>
    #include<iomanip>
    #include<queue>

    #include"BSTTreeAndyJackson.cpp"



    using namespace std;
    //template<class Type>
    //template <class QueueItem>
    int main()
    {
    //Declare the class, struct, and variables
    btree bt;
    node nd;
    int num=0;
    char chr;
    int count=0;

    //queue<int> q;


    //Open the input and output files
    //fin.open("input.txt");
    //fout.open("output1.txt");


    //Priming read into the while loop
    // fin>>num;
    // fin>>chr;
    bt.Input(fin,fout); //The call

    while(!fin.eof())

    { bt.search(num);

    count++;
    fout<<"Step: "<<count<<" "<<"Data Value = "<<num<<" "<<
    "Activity Signal = "<<chr<<endl<<endl;
    if(chr == 'A')
    {
    bt.insert(num);

    }
    else if(chr == 'D')
    {fout<<endl;
    bt.Output("D is not the correct input Activity signal");
    fout<<endl<<endl;
    count--;

    }

    //Call the functions for the list tranversal
    bt.Output("InOrderTranverse = ");
    bt.InOrderTranverse();
    fout<<endl<<endl;

    bt.Output("PreOrder Tranverse = ");
    bt.preOrderTranverse();
    fout<<endl<<endl;

    bt.Output("PostOrder Tranverse = ");
    bt.PostOrderTranverse();
    fout<<endl<<endl;


    bt.Output("LevelOrderTranverse = ");

    //bt.LevelOrder();
    fout<<endl<<endl;


    bt.Output("Total number of Nodes in the tree = ");
    fout<<count;
    fout<<endl<<endl<<endl;


    // fin>>num;
    // fin>>chr;


    }



    return 0;
    }

  2. #2
    Unregistered
    Guest
    I don't understand why you are opening an output stream in the
    function. Make sure you open and close the file at the right time.
    If you don't it will create all kinds of problems. Why are you
    using the ofstream in the function.

  3. #3
    Registered User
    Join Date
    Aug 2001
    Posts
    84

    opening a ofstream in a function

    I am opening a ofstream in a function to see if it will work. Just trying something.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. geting input in C, problem in getting input
    By BujarM in forum C Programming
    Replies: 3
    Last Post: 04-17-2009, 10:38 PM
  2. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 03:51 PM
  3. Input statement problem
    By une in forum C Programming
    Replies: 3
    Last Post: 05-30-2007, 12:16 AM
  4. Problem with File Input & Pointers
    By jenna in forum C++ Programming
    Replies: 9
    Last Post: 12-04-2004, 11:34 PM
  5. Problem with text input
    By newbie in forum C++ Programming
    Replies: 2
    Last Post: 03-10-2002, 04:44 PM

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