Code:
struct name{
char* user;
char* color;
}
name* student = new name[5]; // 5 students
ifstream in;
int i = 0;
in.open ("student.da");
while (!eof){
in.get >> student[i]->user;
in.get >> student[i]->color;
i++;
}
First off, you need to initilize the pointers in your name structure before you can read anything in.
Before that, you need to know how much you're reading in... so we create a buffer (pszBuffer) and read UP TO 255 characters OR until a new line is found. Then we read the length of the buffer, allocate enough memory to store the characters in the buffer, and copy them to our new memory.
Code:
struct name {
char *user;
char *color;
};
// ...
name student[5];
ifstream in("student.da");
char pszBuffer[256];
int count = 0;
while (!in.eof())
{
in.getline(pszBuffer, 255, '\n'); // read in a single line
student[count].user = new char[strlen(pszBuffer) + 1];
strcpy(student[count].user, pszBuffer);
in.getline(pszBuffer, 255, '\n');
student[count].color = new char[strlen(pszBuffer) + 1];
strcpy(student[count].color, pszBuffer);
count++;
}