| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1106 人关注过本帖
标题:菜鸟问题,不明白为什么编译不过~
只看楼主 加入收藏
木瓜君
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:67
专家分:144
注 册:2009-10-17
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:2 
菜鸟问题,不明白为什么编译不过~
程序代码:
// stock1.cpp ?Stock class implementation with constructors, destructor added
#include <iostream>
#include "stock1.h"

// constructors (verbose versions)
Stock::Stock()        // default constructor
{
    std::cout << "Default constructor called\n";
    std::strcpy(company, "no name");
    shares = 0;
    share_val = 0.0;
    total_val = 0.0;
}

Stock::Stock(const char * co, int n, double pr)
{
    std::cout << "Constructor using " << co << " called\n";
    std::strncpy(company, co, 29);
    company[29] = '\0';

    if (n < 0)
    {
        std::cerr << "Number of shares can't be negative; "
                   << company << " shares set to 0.\n";
        shares = 0;
    }
    else
        shares = n;
    share_val = pr;
    set_tot();
}
// class destructor
Stock::~Stock()        // verbose class destructor
{
    std::cout << "Bye, " << company << "!\n";
}

// other methods
void Stock::buy(int num, double price)
{
     if (num < 0)
    {
        std::cerr << "Number of shares purchased can't be negative. "
             << "Transaction is aborted.\n";
    }
    else
    {
        shares += num;
        share_val = price;
        set_tot();
    }
}

void Stock::sell(int num, double price)
{
    using std::cerr;
    if (num < 0)
    {
        cerr << "Number of shares sold can't be negative. "
             << "Transaction is aborted.\n";
    }
    else if (num > shares)
    {
        cerr << "You can't sell more than you have! "
             << "Transaction is aborted.\n";
    }
    else
    {
        shares -= num;
        share_val = price;
        set_tot();
    }
}

void Stock::update(double price)
{
    share_val = price;
    set_tot();
}

void Stock::show()
{
    using std::cout;
    using std::endl;
    cout << "Company: " << company
        << "  Shares: " << shares << endl
        << "  Share Price: $" << share_val
        << "  Total Worth: $" << total_val << endl;
}

提示:
error C2039: 'strcpy' : is not a member of 'std'
 error C2039: 'strncpy' : is not a member of 'std'
怎么改?这是primer plus 上的习题代码来得~~我用vc++的
搜索更多相关主题的帖子: 编译 
2010-01-01 14:54
cnbj
Rank: 2
等 级:论坛游民
威 望:1
帖 子:67
专家分:55
注 册:2008-11-4
收藏
得分:7 
没加头文件#include <string.h>
2010-01-01 15:25
pangding
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:北京
等 级:贵宾
威 望:94
帖 子:6784
专家分:16751
注 册:2008-12-20
收藏
得分:7 
#include <cstring>
2010-01-03 10:07
快速回复:菜鸟问题,不明白为什么编译不过~
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017702 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved