#include <stdlib.h>
#include <iostream.h>
#include <string.h> //strcpy
struct MyRec {
char name[21];
int age;
};
// a declaration which takes up no space in memory
int main () {
MyRec rec1 = {"Tom Jones", 31};
// int are moving to all 4-byte integers
// occupies 23 bytes storage, assuming no extra padding
strcpy (rec1.name, "Tom Jones");
cout << rec1.name << "\n" << rec1.age << endl;
rec1.age=31;
cout << "enter age of dude in my structure char[21]:" << endl;
cin >> rec1.age;
cout << "enter name of dude in my structure char[21]:" << endl;
cin >> rec1.name;
// cin.get(rec1.name, xy); //get including spaces
// stops at enter key
//cin.get also takes initial whitespace
// get up to 21, and also takes enter key
cout << "name = " << rec1.name << " age = " << rec1.age << endl;
//so tell it to get rid of any whitespace
// to read from a file, use payroll.get
// "file_name.get"
// get only applies to strings
// if a single char or number just read it directly.
}
return to top