Hello All,
i have written a program to read data of Persons from a file and fill the data into a dynamically created array of Persons.
i am geting error in line 28
plz help
the 1.txt file can be assumed as:(first line is the no of persons, then names of persons are given with age separated by a dot)
3
abcxyx.10
aadd.12
sda.44
regards
#include <iostream>
#include <fstream>
#include <string>
#include <cstring>
using namespace std;
struct Person
{
char* name[25];
int age;
};
int main()
{
int size;
Person* PersonPointer=0;
ifstream fin;
fin.open("1.txt");
if(fin.is_open())
{
cout << "File opened!";
fin >> size;
PersonPointer = new Person[size];
char temp[25]={'\0'};
for(int i=0; i<size; i++)
{
fin.getline (temp, '.');
strcpy(PersonPointer.name, temp);
//PersonPointer.name = temp;
fin >> PersonPointer[i].age;
}
}
else cout << "error in opening file";
}