title: Way to handle the objects in C++
body: <p>Every time when I run the code Compiler give the error of object already define and I don't know where I am making mistakes in the whole code. </p>
  
  <p>Even if I do this all in one file it is working but I don't know why its not working in this style can anyone help me that where I am doing mistake in this code.</p>
  
  <p>Any help would be appreciated. 
  Thank you</p>
  
  <p><strong>student.h</strong></p>
  
  <pre><code>ifndef STUDENT
  define STUDENT
  
  class Student
  {
  
  public:
      char student_no[10];
      char student_name[20];
      char student_address[20];
      char student_score[20];
      Student();
  
  };
  
  Student::Student()
  {//constructor
      student_no[0] = 0; student_name[0] = 0; student_address[0] = 0;
      student_score[0] = 0;
  }
  
  #endif
  </code></pre>
  
  <p><strong>student.cpp</strong></p>
  
  <pre><code>using namespace std;
  #include "writestr.cpp"
  #include &lt;fstream&gt;
  #include &lt;string.h&gt;
  #include &lt;iostream&gt;
  
  
  
  int main(){
      char filename[20];
      Student s;
      cout &lt;&lt; "Enter the file name:" &lt;&lt; flush;
      cin.getline(filename, 19);
      ofstream stream(filename, ios::out);
      if (stream.fail()) {
          cout &lt;&lt; "File open failed!" &lt;&lt; endl;
          return 0;
      }
      while (1) {
          cin &gt;&gt; s; // read fields of person
          if (strlen(s.student_name) == 0) break;
          // write person to output stream
          stream &lt;&lt; s; // write fields of person
      }
      return 1;
  }
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/e7Fip.png" rel="nofollow noreferrer">Problems occured</a></p>
  
  <p>This is the portion where I write the streaming code.</p>
  
  <p><strong>writestr.cpp</strong></p>
  
  <pre><code>using namespace std;
  #include "readper.cpp"
  #include &lt;fstream&gt;
  #include &lt;string.h&gt;
  #include &lt;iostream&gt;
  
  ostream &amp; operator &lt;&lt; (ostream &amp; stream, Student &amp; s)
  { // insert fields into file
      stream &lt;&lt; s.student_name &lt;&lt; s.student_no &lt;&lt; s.student_address
          &lt;&lt; s.student_score;
      return stream;
  }
  </code></pre>
  
  <p><strong>readper.cpp</strong></p>
  
  <pre><code>using namespace std;
  #include "student.h"
  #include &lt;fstream&gt;
  #include &lt;string.h&gt;
  #include &lt;iostream&gt;   
  istream &amp; operator &gt;&gt; (istream &amp; stream, Student &amp; s)
  { // read fields from input
      cout &lt;&lt; "Enter Student Name, or &lt;cr&gt; to end: " &lt;&lt; flush;
      stream.getline(s.student_name, 30);
  
      if (strlen(s.student_name) == 0) return stream;
      cout &lt;&lt; "Enter Student Name: " &lt;&lt; flush; stream.getline(s.student_name, 30);
      cout &lt;&lt; "Enter Student Id Number: " &lt;&lt; flush; stream.getline(s.student_no, 30);
      cout &lt;&lt; "Enter Address: " &lt;&lt; flush; stream.getline(s.student_address, 30);
      cout &lt;&lt; "Enter Score: " &lt;&lt; flush; stream.getline(s.student_score, 15);
  
      return stream;
  }
  </code></pre>