How to assign/read a member of an object in a stack?
struct item{ char opra; int count; double operand; }; stack<item> S; double test = S.top.operand; it not works, thanks.
You are just making a typo. top in stack is a function, I let you here a working example:
#include <iostream> #include <stack> using namespace std; struct item{ char opra; int count; double operand; }; int main() { item a; a.opra = 'a'; a.count = 3; a.operand = 5.0; stack<item> S; S.push(a); // Stack top cout << S.top().operand; return 0; } Output:
5
S.top.operand-->S.top().operand?