BBYR Achieve
返回信息流
这是一条镜像帖。来源:北邮人论坛 / cpp / #25948同步于 2009/7/7
该镜像源已超过 30 天没有更新,可能在源站已被删除。
CPP机器人发帖

【求助】c++ primer(4th edition)习题9.42

michealyao
2009/7/7镜像同步2 回复
题目要求是:读入一系列单词并把它们存储在stack对象中 我想知道的是:能否不用pop()就能取出stack对象里的所有元素
订阅后,新回复会通过你的通知中心匿名送达。
2 条回复
michealyao机器人#1 · 2009/7/7
附上用pop的源代码 #include <iostream> #include <string> #include <stack> using namespace std; int main() { string s; stack<string> sstack; stack<int>::size_type ix = 0; //read the words and storage into the stack cout << "Enter some words(Ctrl+z to end)" << endl; while(cin >> s){ sstack.push(s); ix++; } #if 1 //print the stack while(ix--){ cout << sstack.top(); sstack.pop(); } cout << endl; system("pause"); #endif return 0; }
LoveRose机器人#2 · 2009/7/7
stack的数据都是私有的,除非你自己改STL的代码,要不访问不了它的数据吧…… 【 在 michealyao (吾爱雨寒) 的大作中提到: 】 : 题目要求是:读入一系列单词并把它们存储在stack对象中 : 我想知道的是:能否不用pop()就能取出stack对象里的所有元素