Thread: What the heck is wrong with my database?

  1. #1
    Linux Forever
    Join Date
    Oct 2002
    Posts
    373

    What the heck is wrong with my database?

    Code:
    #include <iostream>
    #include <fstream>
    #include <stdlib.h>
    #include <iomanip>
    #include <windows.h>
    using namespace std;
    inline void eatline() { while (cin.get() != '\n') continue; }
    struct dog
    {
    char name[20];    //name
    double weight;    //weight
    double b;         //breed
    };
    
    const char * file = "dogs.dat";
    int main ()
    {
        dog d1;
        cout << fixed << right;
    
    
    //show initial contents
        ifstream fin;
        fin.open(file, ios::in |ios::binary);
    //NOTE: Some Systems don't allow ios::binary
        if (fin.is_open())
        {
        cout << "Here are the current contents of the" << file << " file:\n";
        while (fin.read((char *) &d1, sizeof d1))
              {
              cout << setw(20) << d1.name << ": "
                   << setprecision(0) << setw(12) << d1.weight
                   << setprecision(2) << setw(6) << d1.b << "\n";
              }
    }
    fin.close();
    
    //add new data
    ofstream fout(file, ios::out | ios::app | ios::binary);
    //Note: Some systems don't allow ios::binary
    if (!fout.is_open())
    {
        cerr << "Can't open " << file << " file for output:\n";
        exit(1);
    }
    
    cout << "Enter dogs name (enter blank line to quit): \n";
    cin.get(d1.name, 20);
    while (d1.name[0] != '\0')
    {
          eatline();
          cout << "Enter dogs weight: ";
          cin >> d1.weight;
          cout << "Enter breed: ";
          cin >> d1.b;
          eatline();
          fout.write((char *) &d1, sizeof d1);
          cout << "Enter dogs name (Blank line to quit):\n";
          cin.get(d1.name, 20);
    }
    fout.close();
    
    //show revised
           fin.clear();
           fin.open(ios::in | ios::binary);
           if (fin.is_open())
           {
           cout << "Here is the new contents of the " << file << "file:\n";
           while (fin.read((char *) &d1, sizeof d1))
                 {
                 cout << setw(20) << d1.name << ": "
                      << setprecision(0) << setw(12) << d1.weight
                      << setprecision(2) << setw(6) << d1.b << "\n";
                      }
                 }
                 fin.close();
                 cout << "Done.\n";
                return 0;
    }
    i get 2 errors:

    line 65 c:/mydocu~1/c__~1/classes/database.cpp
    no matching function for call to `

    and

    line 362 c:/mingw/include/c__~1/3.2/fstream
    candidates are: void

    respond A.S.A.P thank you!
    This war, like the next war, is a war to end war.

  2. #2
    Registered User
    Join Date
    Aug 2002
    Posts
    170
    See Eibro's post below.
    Last edited by bonkey; 11-11-2002 at 11:01 AM.
    Best Regards,

    Bonkey

  3. #3
    I lurk
    Join Date
    Aug 2002
    Posts
    1,361
    Code:
    fin.open(ios::in | ios::binary);
    You have that on line 65... you need to supply a char * as the first argument (a filename).

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. accessing a database made in Access..
    By willc0de4food in forum Windows Programming
    Replies: 4
    Last Post: 10-10-2005, 07:40 PM
  2. What the heck is wrong with this code?
    By Shadow12345 in forum C++ Programming
    Replies: 4
    Last Post: 09-25-2002, 02:58 PM
  3. What The Heck Is Wrong W/ This?
    By Prodigy in forum C++ Programming
    Replies: 6
    Last Post: 05-05-2002, 03:44 PM
  4. Outputting to a database
    By Robert602 in forum C++ Programming
    Replies: 3
    Last Post: 12-26-2001, 09:03 PM
  5. Replies: 1
    Last Post: 10-09-2001, 10:20 PM