CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
可用分押宝游戏火热进行中... 专题改版:Java Web 专题
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  C/C++ >  C语言

有谁能帮我一把,不胜感谢!

楼主jumpbob(波波)2003-09-02 19:45:14 在 C/C++ / C语言 提问

stack.h文件:  
  #include   <string>  
  #include   <vector>  
  using   namespace   std;  
   
  class   stack{  
  public:  
  bool   push(const   string&);  
  bool   pop(string   &elem);  
  bool   peek(string   &elem);  
  bool   empty()   const   {return   _stack.empty();}  
  bool   full()   const   {   return   _stack.size()==_stack.max_size();}  
  int   size()   const   {return   _stack.size();}  
  private:  
  vector<string>_stack;  
  }  
  stack.cpp文件:  
  #include   "stack.h"  
  #include   <iostream>  
   
  using   namespace   std;  
   
  bool   stack::pop(string   &elem){  
  if   (empty())   return   false;  
  elem=_stack.back();  
  _stack.pop_back();  
  return   true;  
  }  
   
  bool   stack::peek(string   &elem){  
  if   (empty())   return   false;  
          elem=_stack.back();  
  return   true;  
  }  
   
  bool   stack::push(const   string   &elem){  
  if   (full())   return   false;  
  _stack.push_back(elem);  
  return   true;  
  }  
   
  int   main()   {  
          stack   st;  
  string   str;  
  while(cin>>str   &&   !   st.full())  
  st.push(str);  
  if(st.empty()){  
                cout<<"\n"<<"Oops:   no   string   were   read--bailing   out\n";  
        return   0;  
  }  
  st.peek(str);  
  if(st.size()==1   &&   str.empty()){  
                cout<<"\n"<<"Oops:   no   string   were   read--bailing   out\n";  
        return   0;  
  }  
  cout<<"\n"<<"Read   in   "<<st.size()<<"   string!\n"  
                  <<"The   strings,in   reverse   order:\n";  
   
  while(st.size())  
  if(st.pop(str))  
  cout<<str<<"   ";  
       
          cout<<"\n"<<"There   are   now   "<<st.size()  
  <<"elements   in   the   stack!\n";  
  }  
  编译:  
  eleting   intermediate   files   and   output   files   for   project   'stack   -   Win32   Debug'.  
  --------------------Configuration:   stack   -   Win32   Debug--------------------  
  Compiling...  
  stack.cpp  
  c:\program   files\microsoft   visual   studio\vc98\include\iostream(14)   :   error   C2143:   syntax   error   :   missing   ';'   before   'namespace'  
  Error   executing   cl.exe.  
   
  stack.exe   -   1   error(s),   0   warning(s)  
   
  这是essential   c++练习4.1,却报iostream.h错 问题点数:0、回复次数:1Top

1 楼jumpbob(波波)回复于 2003-09-02 22:13:17 得分 0

我的问题呢?Top

相关问题

  • 谁能帮个忙把下面的字符解码~ 不胜感谢
  • 各位大侠,帮帮忙!不胜感谢!
  • 提供源代码,希望大家帮我挑挑错误!!不胜感谢!!!
  • 谁能帮我来点网络里的硬措施,不胜感谢!
  • MultiByteToWideChar()的用法,不胜感谢!!
  • 一个简单的问题,请各位帮帮我这个VC新手!不胜感谢!
  • 谁把大富翁2发给本人(newmon.wei@utstar.com),并提供其在2000底下的用法,不胜感谢
  • 关于sql的问题,我刚学,不知道那里错了,帮忙看看,不胜感谢!
  • findcsdn请来接分,感谢两天来的帮助,问题已经成功解决,不胜感激
  • findcsdn再请来接分,感谢两天来的帮助,问题已经成功解决,不胜感激

关键词

  • stack
  • empty
  • bool
  • elem
  • back
  • full
  • pop
  • push
  • st
  • const

得分解答快速导航

  • 帖主:jumpbob

相关链接

  • C/C++ Blog
  • C/C++类图书
  • C/C++类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
世纪乐知(北京)网络技术有限公司 版权所有, 京 ICP 证 020026 号
北京创新乐知广告有限公司 提供技术支持
Copyright © 2000-2007, CSDN.NET, All Rights Reserved
GongshangLogo