I am trying to read a .info file as a block of data and then get certain values from that data and store them in a struct, and I don't understand the professor's example.
I have a header file that contains a struct:
#ifndef _STRUC_H
#define _STRUC_H
#define NAMELEN 51
#define ADDLEN 125
struct record
{
int id;
char name[NAMELEN];
char address[ADDLEN];
};
#endif
And i have my main function that looks like this:
int main() {
string fileName;
ifstream inFile;
cout << "Please enter a filename: ";
getline(cin,fileName);
inFile.open(fileName);
if(!inFile)
{
cerr << "Could not open: " << fileName << endl;
return 1;
}
cout << endl;
record rec;
inFile.read(reinterpret_cast<char *>(&rec),sizeof(rec));
while(!inFile.eof())
{
cout << "Id : " << rec.id << endl;
cout << "Name: " << rec.name << endl;
cout << "Addr: " << rec.address << "\n" << endl;
inFile.read(reinterpret_cast<char *>(&rec),sizeof(rec));
}
inFile.close();
return 0;
}
What do the values for NAMELEN and ADDLEN do and How did my professor get them?