C++ struct dynamic structure allocation
#include <iostream> #include <string> using namespace std; struct Employee/*from ww w .j av a2s. com*/ { string name; string phoneNo; }; void populate(Employee *); // function prototype needed by main() void dispOne(Employee *); // function prototype needed by main() int main() { char key; Employee *recPoint; cout << "Do you wish to create a new record (respond with y or n): "; key = cin.get(); if (key == 'y') { key = cin.get(); // get the Enter key in buffered input recPoint = new Employee; populate(recPoint); dispOne(recPoint); } else cout << "\nNo record has been created."; return 0; } // Input a name and phone number void populate(Employee *record) { cout << "Enter a name: "; getline(cin,record->name); cout << "Enter the phone number: "; getline(cin,record->phoneNo); return; } // Display the contents of one record void dispOne(Employee *contents){ cout << "\nThe contents of the record just created are:" << "\nName: " << contents->name<< "\nPhone Number: " << contents->phoneNo << endl; return; }