error on include the fstream.h header
<p>I am reading a book "Data Structures and Algorithms in C++" which was published at 2001, I think the c++ compiler should be changed a lot since that time, because I found the code in the book can not be compiled.</p>

<pre><code>#include &lt;fstream.h&gt;
#include &lt;string.h&gt;
</code></pre>

<p>So I Google for the answer, and changed the code to</p>

<pre><code>#include &lt;fstream&gt;
#include &lt;cstring&gt;
using namespace std;
</code></pre>

<p>But when I tried to compile the code, well, I got some error I have not ever seen:</p>

<pre><code>oo@oo:~/raf$ g++ database.cpp personal.cpp student.cpp useDatabase.cpp -o useDatabase
In file included from /usr/include/c++/4.6/ios:45:0,
                 from /usr/include/c++/4.6/istream:40,
                 from /usr/include/c++/4.6/fstream:40,
                 from personal.h:4,
                 from student.h:1,
                 from student.cpp:1:
/usr/include/c++/4.6/bits/ios_base.h: In copy constructor ‘std::basic_ios&lt;char&gt;::basic_ios(const std::basic_ios&lt;char&gt;&amp;)’:
/usr/include/c++/4.6/bits/ios_base.h:788:5: error: ‘std::ios_base::ios_base(const std::ios_base&amp;)’ is private
/usr/include/c++/4.6/bits/basic_ios.h:64:11: error: within this context
In file included from /usr/include/c++/4.6/istream:41:0,
                 from /usr/include/c++/4.6/fstream:40,
                 from personal.h:4,
                 from student.h:1,
                 from student.cpp:1:
/usr/include/c++/4.6/ostream: In copy constructor ‘std::basic_ostream&lt;char&gt;::basic_ostream(const std::basic_ostream&lt;char&gt;&amp;)’:
/usr/include/c++/4.6/ostream:57:11: note: synthesized method ‘std::basic_ios&lt;char&gt;::basic_ios(const std::basic_ios&lt;char&gt;&amp;)’ first required here 
In file included from student.cpp:1:0:
student.h: In function ‘std::ostream&amp; operator&lt;&lt;(std::ostream&amp;, Student&amp;)’:
student.h:17:39: note: synthesized method ‘std::basic_ostream&lt;char&gt;::basic_ostream(const std::basic_ostream&lt;char&gt;&amp;)’ first required here 
student.h:15:18: error:   initializing argument 1 of ‘std::ostream&amp; Student::writeLegibly(std::ostream)’
student.cpp: At global scope:
student.cpp:24:10: error: prototype for ‘std::ostream&amp; Student::writeLegibly(std::ostream&amp;)’ does not match any in class ‘Student’
student.h:15:18: error: candidate is: std::ostream&amp; Student::writeLegibly(std::ostream)
student.cpp: In member function ‘std::istream&amp; Student::readFromConsole(std::istream&amp;)’:
student.cpp:34:5: error: ‘cout’ was not declared in this scope
In file included from /usr/include/c++/4.6/ios:45:0,
                 from /usr/include/c++/4.6/ostream:40,
                 from /usr/include/c++/4.6/iostream:40,
                 from useDatabase.cpp:1:
/usr/include/c++/4.6/bits/ios_base.h: In copy constructor ‘std::basic_ios&lt;char&gt;::basic_ios(const std::basic_ios&lt;char&gt;&amp;)’:
/usr/include/c++/4.6/bits/ios_base.h:788:5: error: ‘std::ios_base::ios_base(const std::ios_base&amp;)’ is private
/usr/include/c++/4.6/bits/basic_ios.h:64:11: error: within this context
In file included from /usr/include/c++/4.6/iostream:40:0,
                 from useDatabase.cpp:1:
/usr/include/c++/4.6/ostream: In copy constructor ‘std::basic_ostream&lt;char&gt;::basic_ostream(const std::basic_ostream&lt;char&gt;&amp;)’:
/usr/include/c++/4.6/ostream:57:11: note: synthesized method ‘std::basic_ios&lt;char&gt;::basic_ios(const std::basic_ios&lt;char&gt;&amp;)’ first required here 
In file included from useDatabase.cpp:2:0:
student.h: In function ‘std::ostream&amp; operator&lt;&lt;(std::ostream&amp;, Student&amp;)’:
student.h:17:39: note: synthesized method ‘std::basic_ostream&lt;char&gt;::basic_ostream(const std::basic_ostream&lt;char&gt;&amp;)’ first required here 
student.h:15:18: error:   initializing argument 1 of ‘std::ostream&amp; Student::writeLegibly(std::ostream)’
oo@oo:~/raf$ 
</code></pre>

<p>I spent a lot of time to Google for the answer, but got even more error. Maybe I should register a Github account and upload my code there.</p>

<p>database.cpp</p>

<pre><code>#include "database.h"

template&lt;class T&gt; Database&lt;T&gt;::Database() {
    cout &lt;&lt; "File name: ";
    cin &gt;&gt; fName;
}

template&lt;class T&gt; void Database&lt;T&gt;::add(T&amp; d){
    database.open(fName, ios::in|ios::out|ios::binary);
    database.seekp(0, ios::end);
    d.writeToFile(database);
    database.close();
}

template&lt;class T&gt; void Database&lt;T&gt;::modify(const T&amp; d){
    T tmp;
    database.open(fName, ios::in|ios::out|ios::binary);
    while(!database.eof()){
        tmp.readFromFile(database);
        if (tmp == d){
            cin &gt;&gt; tmp;
            database.seekp(-d.size(), ios::cur);
            tmp.writeToFile(database);
            database.close();
            return;
        }
    }
    database.close();
    cout &lt;&lt; "The record to be modified is not in the database\n";
}

template&lt;class T&gt; bool Database&lt;T&gt;::find(const T&amp; d){
    T tmp;
    database.open(fName, ios::in|ios::binary);
    while(!database.eof()){
        tmp.readFromFile(database);
        if (tmp == d){
            database.close();
            return true;
        }
    }
    database.close();
    return false;
}

template&lt;class T&gt; ostream&amp; Database&lt;T&gt;::print(ostream&amp; out){
    T tmp;
    database.open(fName, ios::in|ios::binary);
    while(1){
        tmp.readFromFile(database);
        if (database.eof())
            break;
        out &lt;&lt; tmp &lt;&lt; endl;
    }
    database.close();
    return out;
}

template&lt;class T&gt; void Database&lt;T&gt;::run() {
    char option[5];
    T rec;
    cout &lt;&lt; "1.Add 2.Find 3.Modify a record 4.Exit\n";
    cout &lt;&lt; "Enter an option: ";
    cin.getline(option, 4);
    while (cin.getline(option, 4)){
        if (*option == '1'){
            cin &gt;&gt; rec;
            add(rec);
        }
        else if (*option == '2'){
            rec.readKey();
            cout &lt;&lt; "The record is ";
            if (find(rec) == false)
                cout &lt;&lt; "not ";
            cout &lt;&lt; "in the database\n";
        }
        else if (*option == '3'){
            rec.readKey();
            modify(rec);
        }
        else if (*option != '4'){
            cout &lt;&lt; "Wrong option\n";
        }
        else return;
        cout &lt;&lt; *this;
        cout &lt;&lt; "Enter an option";
    }
}
</code></pre>

<p>database.h</p>

<pre><code>#ifndef DATABASE
#define DATABASE
#include &lt;fstream&gt;
#include &lt;iostream&gt;
using namespace std;

template&lt;class T&gt; class Database{
    public:
        Database();
        void run();
    private:
        fstream database;
        char fName[20];
        ostream&amp; print(ostream&amp;);
        void add(T&amp;);
        bool find(const T&amp;);
        void modify(const T&amp;);
        friend ostream&amp; operator&lt;&lt;(ostream&amp; out, Database&amp; db) {
            return db.print(out);
        }
};
#endif
</code></pre>

<p>personal.cpp</p>

<pre><code>#include "personal.h"
#include &lt;iostream&gt;

Personal::Personal() : nameLen(10), cityLen(10) {
    name = new char[nameLen + 1];
    city = new char[cityLen + 1];
}

Personal::Personal(char *ssn, char *n, char *c, int y, long s) : nameLen(10), cityLen(10) {
    name = new char[nameLen + 1];
    city = new char[cityLen + 1];
    strcpy(SSN, ssn);
    strcpy(name, n);
    strcpy(city, c);
    year = y;
    salary = s;
}

void Personal::writeToFile(fstream&amp; out) const {
    out.write(SSN, 9);
    out.write(name, nameLen);
    out.write(city, cityLen);
    out.write(reinterpret_cast&lt;const char*&gt;(&amp;year), sizeof(int));
    out.write(reinterpret_cast&lt;const char*&gt;(&amp;salary), sizeof(int));
}

void Personal::readFromFile(fstream&amp; in) {
    in.read(SSN, 9);
    in.read(name, nameLen);
    in.read(city, cityLen);
    in.read(reinterpret_cast&lt;char *&gt;(&amp;year), sizeof(int));
    in.read(reinterpret_cast&lt;char *&gt;(&amp;salary), sizeof(int));
}

void Personal::readKey() {
    char s[80];
    cout &lt;&lt; "Enter SSN: ";
    cin.getline(s, 80);
    strncpy(SSN, s, 9);
}

ostream&amp; Personal::writeLegibly(ostream&amp; out){
    SSN[9] = name[nameLen] = city[cityLen] = '\0';
    out &lt;&lt; "SSN = " &lt;&lt; SSN &lt;&lt; ", name = " &lt;&lt; name
        &lt;&lt; ", city = " &lt;&lt; city &lt;&lt; ", year = " &lt;&lt; year
        &lt;&lt; ", salary = " &lt;&lt; salary;
    return out;
}

istream&amp; Personal::readFromConsole(istream&amp; in){
    char s[80];
    cout &lt;&lt; "SSN: ";
    in.getline(s, 80);
    strncpy(SSN, s, 9);
    cout &lt;&lt; "Name: ";
    in.getline(s, 80);
    strncpy(name, s, nameLen);
    cout &lt;&lt; "City: ";
    in.getline(s, 80);
    strncpy(city, s, cityLen);
    cout &lt;&lt; "Birthyear: ";
    in &gt;&gt; year;
    cout &lt;&lt; "Salary: ";
    in &gt;&gt; salary;
    in.getline(s, 80); //get '\n'
    return in;
}
</code></pre>

<p>personal.h</p>

<pre><code>#ifndef PERSONAL
#define PERSONAL

#include &lt;fstream&gt;
#include &lt;cstring&gt;
using namespace std;

class Personal {
    public:
        Personal();
        Personal(char*, char*, char*, int, long);
        void writeToFile(fstream&amp;) const;
        void readFromFile(fstream&amp;);
        void readKey();
        int size() const {
            return 9 + nameLen + cityLen + sizeof(year) + sizeof(salary);
        }
        bool operator==(const Personal&amp; pr) const{
            return strcmp(pr.SSN, SSN) == 0;
        }

    protected:
        const int nameLen, cityLen;
        char SSN[10], *name, *city;
        int year;
        long salary;
        ostream&amp; writeLegibly(ostream&amp;);
        friend ostream&amp; operator&lt;&lt;(ostream&amp; out, Personal&amp; pr){
            return pr.writeLegibly(out);
        }
        istream&amp; readFromConsole(istream&amp;);
        friend istream&amp; operator&gt;&gt;(istream&amp; in, Personal&amp; pr){
            return pr.readFromConsole(in);
        }
};

#endif
</code></pre>

<p>student.cpp</p>

<pre><code>#include "student.h"

Student::Student() : majorLen(10) {
    Personal();
    major = new char[majorLen + 1];
}

Student::Student(char *ssn, char *n, char *c, int y, long s, char *m): majorLen(11){
    Personal(ssn, n, c, y, s);
    major = new char[majorLen + 1];
    strcpy(major, m);
}

void Student::writeToFile(fstream&amp; out) const {
    Personal::writeToFile(out);
    out.write(major, majorLen);
}

void Student::readFromFile(fstream&amp; in) {
    Personal::readFromFile(in);
    in.read(major, majorLen);
}

ostream&amp; Student::writeLegibly(ostream &amp;out){
    Personal::writeLegibly(out);
    major[majorLen] = '\0';
    out &lt;&lt; ", major = " &lt;&lt; major;
    return out;
}

istream&amp; Student::readFromConsole(istream&amp; in){
    Personal::readFromConsole(in);
    char s[80];
    cout &lt;&lt; "Major: ";
    in.getline(s, 80);
    strncpy(major, s, 9);
    return in;
}
</code></pre>

<p>student.h</p>

<pre><code>#include "personal.h"

class Student : public Personal {
    public:
        Student();
        Student(char*, char*, char*, int, long, char*);
        void writeToFile(fstream&amp;) const;
        void readFromFile(fstream&amp;);
        int size() const{
            return Personal::size() + majorLen;
        }
    protected:
        char *major;
        const int majorLen;
        ostream&amp; writeLegibly(ostream);
        friend ostream&amp; operator&lt;&lt;(ostream&amp; out, Student&amp; sr){
            return sr.writeLegibly(out);
        }
        istream&amp; readFromConsole(istream&amp;);
        friend istream&amp; operator&gt;&gt;(istream&amp; in, Student&amp; sr){
            return sr.readFromConsole(in);
        }
};
</code></pre>

<p>useDatabase.cpp</p>

<pre><code>#include &lt;iostream&gt;
#include "student.h"
#include "personal.h"
#include "database.h"

int main(){
    Database&lt;Personal&gt; db;
    db.run();
}
</code></pre>
