Store results of std::stack .pop() method into a variable

前端 未结 4 1506
执念已碎
执念已碎 2020-12-01 15:55

I\'d like to do the following:

std::stack  s;
int h = 0;
s.push(2);
h = s.pop();

Such as to have h hold the value 2

4条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-01 16:23

    You can use:

    h = s.top();
    

    then after that use(if you want to remove the most recent value otherwise do nothing)

     s.pop();
    

    It works the same way!!

提交回复
热议问题