I have a struct:
struct Vehicle
{
char ad; // Arrival departure char
string license; // license value
int arrival; // arrival in military time
};
I want to store all the values in the struct in a stack.
I can store one value in the stack by doing:
stack<string> stack; // STL Stack object
Vehicle v; //vehicle struct object
stack.push(v.license);
How can I store a the whole struct in the stack so I can later access the char, int, and, string?
The type between the
<
and>
is what your stack will hold. The first one heldstring
s, you can have one that holdsVehicles
:What would happen when v goes out of scope? I guess you'd better created object on the heap and stores pointers to them in your stack:
How could I push g in stack ?
Simple, just replace
string
forVehicle
and an instance ofstring
for an instance ofVehicle
: