CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
山寨机中的战斗机! 程序优化工程师到底对IT界有没有贡献
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  C/C++ >  C语言

急救!!DEV C++怎么用?

楼主common_man(吾与点也)2002-08-20 16:01:43 在 C/C++ / C语言 提问

小弟下载了一个DEV   C++,可敲入书(c++primer第十七章的例子)上的代码却老是编译不能通过,有上百个错误,是不是设置不对,请高手指教!! 问题点数:100、回复次数:15Top

1 楼langhaixin(C++如此多娇,引无数高手尽折腰!)回复于 2002-08-20 16:04:36 得分 0

先把代码贴出来看看!Top

2 楼pppplato(cynic)回复于 2002-08-20 16:07:38 得分 0

我正在用dev   c++感觉还不错Top

3 楼dnawym(MinGX)回复于 2002-08-20 16:12:31 得分 10

仔细的检查嘛,尤其是符号问题,要看清楚哈!Top

4 楼common_man(吾与点也)回复于 2002-08-20 16:36:14 得分 0

代码如下:  
  /******************Account.h*******************************/  
  #ifndef   ACCOUNT_H  
  #define   ACCOUNT_H  
   
  //   #include   <new>  
  //   #include   <cstddef>  
  #include   <new.h>  
  #include   <stddef.h>  
   
  #include   <utility>  
  #include   <vector>  
  #include   <string>  
   
  typedef   pair<string,double>   value_pair;  
     
  class   Account   {  
  public:  
  Account()   :     _balance(   0.0   ),   _acct_nmbr(   0   )   {}  
   
  Account(   const   char*,   double=0.0   );  
  Account(   const   string&,   double=0.0   );  
  Account(   const   Account   &rhs   );  
  Account&   operator=(   const   Account   &rhs   );  
   
  string               name()         const   {   return   _name;   }  
  double               balance()   const   {   return   _balance;   }  
                  unsigned   int   account()   const   {   return   _acct_nmbr;   }  
   
    static   Account*   init_heap_array(  
            vector<value_pair>   &init_values,  
            vector<value_pair>::size_type   elem_count   =   0   );  
   
    static   void   dealloc_heap_array(   Account*,   size_t   );  
   
  private:  
  string               _name;  
    unsigned   int   _acct_nmbr;  
    double               _balance;  
   
  unsigned   int   get_unique_acct_nmbr()   const;  
  };  
   
  inline   Account::  
  Account(   const   char*   name,   double   opening_bal   )  
                :   _name(   name   ),   _balance(   opening_bal   )  
  {  
                  _acct_nmbr   =   get_unique_acct_nmbr();  
  }  
   
  inline   Account::  
  Account(   const   string   &name,   double   opening_bal   )  
                :   _name(   name   ),   _balance(   opening_bal   )  
  {  
                  _acct_nmbr   =   get_unique_acct_nmbr();  
  }  
   
  inline   Account::  
  Account(   const   Account   &rhs   )  
                :   _name(   rhs._name   )  
  {  
                  _balance   =   rhs._balance;  
                  _acct_nmbr   =   get_unique_acct_nmbr();  
  }  
   
  inline   Account&   Account::  
  operator=(   const   Account   &rhs   )  
  {  
                  //   guard   against   self-assignment  
                  if   (   this   !=   &rhs   )  
                  {  
                                  //   invokes   string::operator=(const   string&   )  
                                  _name   =   rhs._name;  
                                  _balance   =   rhs._balance;  
                  }  
   
                  return   *this;  
  }  
   
  #endif  
   
  /***************Account.c*****************************/  
  #include   "Account.h"  
   
  unsigned   int   Account::  
  get_unique_acct_nmbr()   const  
  {  
  static   unsigned   int   acct_nmbr   =   1000000;  
  return   ++acct_nmbr;  
  }  
   
  /*   init_heap_array(),  
    *           declared   as   a   static   member   function,  
    *           provides   for   allocation   and   initialization  
    *           of   heap   array   of   class   objects.  
    *  
    *   init_values:   initial   value   pairs   for   array   elements  
    *   elem_count:   number   of   elements   in   array  
    *                           if   0,   array   is   size   of   init_values   vector.  
    */  
  Account*   Account::  
  init_heap_array(   vector<value_pair>   &init_values,  
                                    vector<value_pair>::size_type   elem_count   )    
  {  
          vector<   value_pair   >::size_type    
            vec_size   =   init_values.size();  
   
          if   (   vec_size   ==   0   &&   elem_count   ==   0   )  
            return   0;  
   
          //   size   of   array   to   allocate   is   either   elem_count  
          //   or,   if   elem_count   is   0,   size   of   vector   ...  
          size_t   elems   =    
  elem_count   ?   elem_count   :   vec_size;  
   
          //   grab   a   chunk   of   raw   memory   to   store   array  
          char   *p   =   new   char[sizeof(Account)*elems];  
   
          //   individually   initialize   each   array   element    
          int   offset   =   sizeof(   Account   );  
          for   (   int   ix   =   0;   ix   <   elems;   ++ix   )    
          {  
    //   offset   to   the   ixth   element.  
    //   if   an   initial   value   pair   is   provided,    
    //         pass   that   pair   to   the   constructor;  
    //   otherwise,   invoke   the   default   constructor  
     
    if   (   ix   <   vec_size   )  
                        new(   p+offset*ix   )   Account(   init_values[ix].first,  
                                                                                    init_values[ix].second   );  
    else   new(   p+offset*ix   )   Account;  
          }  
           
          //   ok:   elements   allocated   and   initialized;    
          //           return   pointer   to   first   element  
          return   (Account*)p;  
  }  
   
  void   Account::  
  dealloc_heap_array(   Account   *ps,   size_t   elems   )    
  {  
          for   (   int   ix   =   0;   ix   <   elems;   ++ix   )    
                              ps[ix].Account::~Account();  
           
          delete   []   reinterpret_cast<char*>(ps);  
  }  
     
  /************************main.c*******************************/  
  #include   "Account.h"  
  #include   <utility>  
  #include   <iostream.h>  
  #include   <iomanip.h>  
   
  /**  
    **  
    [   0   ]   {   Acct#   1000001   --   Mr.   Happy               Balance:   $7000.49   }  
    [   1   ]   {   Acct#   1000002   --   Mr.   Grumpy             Balance:   $1000.55   }  
    [   2   ]   {   Acct#   1000003   --   Mr.   Doc                   Balance:   $3000.72   }  
    [   3   ]   {   Acct#   1000004   --   Mr.   Sleepy             Balance:   $1999.99   }  
    [   4   ]   {   Acct#   1000005   --   Mr.   Sneezy             Balance:   $4100.54   }  
    [   5   ]   {   Acct#   1000006   --   Mr.   Bashful           Balance:   $8500.08   }  
    [   6   ]   {   Acct#   1000007   --   Mr.   Dopey               Balance:   $1000.01   }  
    **  
    **/  
   
  int   main()  
  {  
          vector<   value_pair   >   init_values;  
   
          init_values.push_back(   make_pair(   string(   "Mr.   Happy"   ),       7000.49   ));  
          init_values.push_back(   make_pair(   string(   "Mr.   Grumpy"   ),     1000.55   ));  
          init_values.push_back(   make_pair(   string(   "Mr.   Doc"   ),           3000.72   ));  
          init_values.push_back(   make_pair(   string(   "Mr.   Sleepy"   ),     1999.99   ));  
          init_values.push_back(   make_pair(   string(   "Mr.   Sneezy"   ),     4100.54   ));  
          init_values.push_back(   make_pair(   string(   "Mr.   Bashful"   ),   8500.08   ));  
          init_values.push_back(   make_pair(   string(   "Mr.   Dopey"   ),       1000.01   ));  
   
          Account   *pact   =   Account::init_heap_array(   init_values   );  
   
          for   (   int   ix   =   0;   ix   <   7;   ++ix   )  
          {  
      cout   <<   "[   "   <<   ix   <<   "   ]   {   Acct#   "  
                <<   pact[   ix   ].account()   <<   "   --   "  
                <<   pact[   ix   ].name()   <<   "\t   Balance:   $"  
                <<   setprecision(   7   )  
                <<   pact[   ix   ].balance()   <<   "   }\n";  
          }  
   
          Account::dealloc_heap_array(   pact,   init_values.size()   );  
  }  
  各位帮忙看看Top

5 楼virginsoldier(北欧野马——哈根)回复于 2002-08-20 16:51:32 得分 10

楼主,你的头文件都没有.h,是想用名字空间吧?可是你的代码中为什么没有“using   namespace   std;”呢?  
  Top

6 楼dejoy(燕青)回复于 2002-08-20 16:58:44 得分 10

要使用using   namespace   std;  
  最好把头文件加上.h,我试过在bcb中不加.h可以,但在devc++中就会报错.Top

7 楼common_man(吾与点也)回复于 2002-08-20 17:04:14 得分 0

upTop

8 楼common_man(吾与点也)回复于 2002-08-20 17:19:53 得分 0

快来救我!!!!Top

9 楼TLFLY(一意孤行)回复于 2002-09-04 09:37:36 得分 10

我试了你的程序,在我的机器上正常啊,  
  你是不是应该新建一个工程阿?   选console的  
  你是怎么设置的?Top

10 楼stidio_zhougang(回头是岸)回复于 2002-09-04 11:46:25 得分 10

在编译后面加上这个   -lstdc++Top

11 楼hhdsq(流氓宝宝)回复于 2002-09-04 11:50:39 得分 10

你是不是没有安装库文件啊?Top

12 楼liubear()回复于 2002-09-04 12:39:10 得分 10

using   namespace   std;  
  Top

13 楼common_man(吾与点也)回复于 2002-09-09 21:15:57 得分 0

小弟我还是搞不定啊!  
  哪位大哥能不能说详细点,谢了,先!Top

14 楼phoenixzz(小百货)回复于 2002-09-09 21:20:10 得分 10

自己摸索吧!Top

15 楼i_doit(呆呆兔)回复于 2002-09-09 21:47:12 得分 20

using   namespace   std都不知道,就看第十一章了!!!  
   
  打好基础再提高吗,侯sir说勿在浮沙驻高台啊!!!Top

相关问题

  • Dev-C++ 怎么啦?
  • Dev C++ 怎么用啊?
  • DEV C++
  • 几道c语言考试题,急救!
  • 急救命啊,C++ Primer问题
  • 急救~~~~C语言课程设计
  • 急救,求c++ builder 6.0下载地址
  • 关于dev c++
  • 关于Dev-C++
  • 关于dev-c++

关键词

  • c++
  • vector
  • nmbr
  • acct
  • account
  • balance
  • mr
  • rhs
  • pair
  • bal

得分解答快速导航

  • 帖主:common_man
  • dnawym
  • virginsoldier
  • dejoy
  • TLFLY
  • stidio_zhougang
  • hhdsq
  • liubear
  • phoenixzz
  • i_doit

相关链接

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

广告也精彩

反馈

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