Reading File & Storing In Class Objects

I've a text file : Random.txt which comprises of
Jade
12MS234
Male
18
Rocky
12MS324
Male
18
Marx
12MS632
Male
18

Now in my program i've a class
class stud
{
char name[10];
char reg[10];
char gender[10];
int age;
};
Now I've to write a code in c++, where i've to read the given data and store this into 3 objects of stud class(array of objects) ...then further i've to manipulate the above stored data...
I think i'm getting error while storing...variables are showing random characters...
Please give me the code.for this program..in C++
Show what you have done so far.
This is a class, so all of the members are private by default. You do not appear to have a constructor or any other member functions that would fill in the data so I imagine that you are trying to access the members directly. Either:

A.) Make the members public.

B.) Change the class to a struct.

or C.) Add a public function that will allow you to access these data members from outside of the class.

Any one of the above will fix your issue.

EDIT: The constructor has to be public to be of any use to you.
Last edited on
Topic archived. No new replies allowed.