C++ Hhhhheeeeeelllllllpppppppp!!!!!!!!!!!!!!!!!!!!!!

Discussion in 'Tech Talk' started by Jon509, Apr 11, 2005.

  1. Jon509

    Jon509

    Messages:
    250
    Likes Received:
    0
    Joined:
    Nov 18, 2002
    Location:
    southeast
    My fiance trying to get 2 files to merge in asending order.

    I have List 1. Integers are 1, 3, 5, 7
    I have List 2. Integers are 2, 4, 6, 8

    I have List 3. I need to merge the 2 lists together in asending order into this file and output from this file.

    She is struggling and I can't seem to find anything that will help her out. They are making her do this for a teaching degree in math. Why...I'll never understand. Thanks in advance for the help

    Jon
     
  2. Jon509

    Jon509

    Messages:
    250
    Likes Received:
    0
    Joined:
    Nov 18, 2002
    Location:
    southeast
    Nevermind the above rambling. That is done. Now we are trying to get a merge print for the file. Following is the source code she is using for the output

    void PrintMerge(){

    ofstream outFile;
    outFile.open("MillerKelli.out");
    while(!outFile.eof()){
    int ch;
    outFile.get(ch);
    cout << ch;
    }
    outFile.close();

    All of this is of course in with the rest of the file and is ended properly. The bold part is where the error is occuring.
    Thanks
    Jon

    Oh yeah the error is "No matching function for call tp`"
     

  3. Dandapani

    Dandapani

    Messages:
    8,216
    Likes Received:
    13
    Joined:
    Mar 24, 2004
    Location:
    Gulf side Florida
    Why are you trying to input from the output file?

    Why are you checking EOF on the output file?

    If you want to read the file you need to fix the stream object:
    Code:
        ifstream inFile;
        inFile.open("MillerKelli.out");
        while(!inFile.eof()){
            int ch;
            inFile.get(ch);
            cout << ch;
        }   
        inFile.close();
    
    It's not the best approach since you will reach eof before you test for it.

    This is better:
    Code:
        ifstream inFile;
        inFile.open("MillerKelli.out");
        int ch; 
        while(inFile.get(ch)) {
            cout << ch;
        }   
        inFile.close();
    
     
  4. greenlead

    greenlead

    Messages:
    326
    Likes Received:
    0
    Joined:
    Jul 30, 2004
    Location:
    NE Indiana
    Why don't you give ch an initial value?

    int ch=0;
     
  5. Dandapani

    Dandapani

    Messages:
    8,216
    Likes Received:
    13
    Joined:
    Mar 24, 2004
    Location:
    Gulf side Florida
    no need. it gets filled in by the .get(ch)...