Build the following program:
#include <iostream>
#include <stack>
using namespace std;
struct Register{
string name;
int birth;
char sex;
void Insert(string st_name,int st_birth, char st_sex){
name=st_name;
birth=st_birth;
sex=st_sex;
}
};
stack <Register> stack_register;
int main(void){
Register data[5];
data[0].Insert("Pkrtvx",151,'M');
stack_register.push(data[0]);
data[1].Insert("IKXS_36080",159,'M');
stack_register.push(data[1]);
return 0;
}
My questions:
I'm inserting the data of struct
into my stack
in the correct way?
How do I show the top element in this case? Because whenever I use the finished top it returns an error.
See the code below to understand:
#include <iostream>
#include <stack>
using namespace std;
struct Register{
string name;
int birth;
char sex;
void Insert(string st_name,int st_birth, char st_sex){
name=st_name;
birth=st_birth;
sex=st_sex;
}
};
stack <Register> stack_register;
int main(void){
Register data[5];
data[0].Insert("IKXS_36080",125,'M');
stack_register.push(data[0]);
data[1].Insert("IKXS_36080",105,'M');
stack_register.push(data[1]);
cout << stack_register.top(); //O erro estar aqui
return 0;
}