Can Dynamic Array be used only in classes and struct?
<p>can anyone pliz let me know what am i doing wring in the following code. Also pliz let me know if this method only works with classes and struct? I was trying to solve this using one dim array but was not successful. Using structs to compile this also seems challenging. Any help will be appreciated.Kind Regards</p>

<pre><code>   /*
The text file looks like this:
2
ID  MARK
S11 10
S22 20
*/
#include &lt;iostream&gt;
#include &lt;fstream&gt;
#include &lt;string&gt;

using namespace std;

struct student
{
    string id;
    int mark;
};

void discard(ifstream &amp;inp);//function to discard lines in text files

int main()
{
//varaible declaration

    char c;
    string read;//to read the number of students in the text file
    int total_rec; //to record the number of students in the text file

    student *studinfo;

ifstream input;

input.open("c:\\students.txt");


    input &gt;&gt; read &gt;&gt; total_rec;

    studinfo = new student[total_rec]; //new dyanamic array
    student *studptr = studinfo;


    discard(input);//discarding two tiltles in the text files
    discard(input);
    while(!input.eof())
    {
        input &gt;&gt; studptr[total_rec].id &gt;&gt; studptr[total_rec].mark;

        total_rec++;
        studptr++;
        input.get(c);
    }

    studptr = studinfo; //making studptr point back to where it started

    //prinitng the information in the text file
    for (int i = 0;i&lt;total_rec;i++)
    {
    cout &lt;&lt; studptr[i].id &lt;&lt; " " &lt;&lt; studptr[i].mark;
    cout &lt;&lt; endl;

    }
    studptr = studinfo;

    delete [] studptr; //deallocating memomory from heap



system("pause");
return 0;
}

void discard(ifstream &amp;inp)
{
char c;
    do
    inp.get(c);
    while(c!='\n');
}
</code></pre>
