How to insert struct data to a file? : <p>I've been working on a records system, everything looks good but </p>

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


using namespace std;

struct students{
    string studentID;
    string surname;
    string firstname;
    string birthdate;
    string sex;
};

int main()
{
    fstream collection;
    string filename;
    short choice;



    do{
        int ctr=1;
        system("cls");
        if(collection.is_open()){
                cout&lt;&lt;"Active File: ["&lt;&lt;filename&lt;&lt;"]"&lt;&lt;endl;
        }else{
                cout&lt;&lt;"Active File|: [None opened]"&lt;&lt;endl;
        }

        cout&lt;&lt;"[1] Create new file"&lt;&lt;endl;
        cout&lt;&lt;"[2] Open existing file"&lt;&lt;endl;
        cout&lt;&lt;"[3] Manage data"&lt;&lt;endl;
        cout&lt;&lt;"[4] Exit"&lt;&lt;endl;
        cout&lt;&lt;"Enter operation index: ";
        cin&gt;&gt;choice;
        switch(choice){
        case 1:
            cout&lt;&lt;"Enter file name: ";
            cin&gt;&gt;filename;
            collection.open(filename, std::fstream::in | std::fstream::out | std::fstream::app);
            collection&lt;&lt;"------------------------------------------------------------------------------"&lt;&lt;endl;
            collection&lt;&lt;"Rec \t Student ID \t Surname \t Firstname \t Birthdate \t Sex \t"&lt;&lt;endl;
            collection&lt;&lt;"------------------------------------------------------------------------------"&lt;&lt;endl;
            collection.close();
            collection.open(filename, std::fstream::in | std::fstream::out | std::fstream::app);
            break;
        case 2:
            cout&lt;&lt;"Enter file name: ";
            cin&gt;&gt;filename;
            collection.open(filename, std::fstream::in | std::fstream::out | std::fstream::app);
            break;
        case 3:
            string lines;
            char menu;
            students student[10];

            do{
                ifstream collection(filename, std::fstream::in | std::fstream::out | std::fstream::app);
                if(collection.is_open()){
                    cout&lt;&lt;"Active File: ["&lt;&lt;filename&lt;&lt;"]";
                    system("cls");
                    while(getline(collection,lines)){
                    cout&lt;&lt;lines&lt;&lt;endl;
                    }
                }
                collection.close();

                cout&lt;&lt;"[A]dd  [E]dit [D]elete  [S]ort  [F]ilter  Sa[V]e  e[X]it";
                cin&gt;&gt;menu;

                if(menu=='A'){
                    string lines2;
                    collection.open(filename,ios::app);
                    system("cls");

                    ifstream collection(filename, std::fstream::in | std::fstream::out | std::fstream::app);
                        if(collection.is_open()){
                            while(getline(collection,lines)){
                                cout&lt;&lt;lines&lt;&lt;endl;
                            }
                        }

                    cout&lt;&lt;endl&lt;&lt;"Adding data to "&lt;&lt;filename&lt;&lt;endl;
                    cout&lt;&lt;"Student ID: ";
                    cin&gt;&gt;student[ctr].studentID;
                    cout&lt;&lt;"Surname: ";
                    cin&gt;&gt;student[ctr].surname;
                    cout&lt;&lt;"Firstname: ";
                    cin&gt;&gt;student[ctr].firstname;
                    cout&lt;&lt;"Birthdate: ";
                    cin&gt;&gt;student[ctr].birthdate;
                    cout&lt;&lt;"Sex: ";
                    cin&gt;&gt;student[ctr].sex;
</code></pre>

<p>Why do I keep getting errors here?</p>

<pre><code>                    //data insertion code heree
                    collection.open(filename, std::fstream::in | std::fstream::out | std::fstream::app);
                    collection&lt;&lt;ctr&lt;&lt;"\t"student[ctr].studentID&lt;&lt;"\t"student[ctr].surname&lt;&lt;"\t"student[ctr].firstname&lt;&lt;"\t"student[ctr].birthdate&lt;&lt;"\t"student[ctr].sex&lt;&lt;endl;

                    collection.close();
                    ctr++;
                }else if(menu=='E'){

                }else if(menu=='D'){

                }else if(menu=='F'){

                }else if(menu=='V'){
                    cout&lt;&lt;"Saving file..."&lt;&lt;endl;
                    collection.close();
                    cout&lt;&lt;"File saved."&lt;&lt;endl;
                    system("pause");
                }else{
                    cout&lt;&lt;"Invalid input."&lt;&lt;endl;
                    system("pause");
                };
            }while(menu!='X');
            break;
        }
    }while(choice!=4);

    }
</code></pre>

<p>Why am I getting error: no match for 'operator&lt;&lt;' in 'collection &lt;&lt; ctr'| errors? The code worked on the early part of the system and it just didn't work.</p>
