| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 720 人关注过本帖
标题:高手来看下
取消只看楼主 加入收藏
广夜
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2008-1-5
收藏
 问题点数:0 回复次数:0 
高手来看下
#include"name.h"

#include<string>

using std::string;

#include<iostream>

using std::ostream;
using std::istream;

#include<iomanip>

using std::setw;
using std::left;

#include<cstring>

using std::strlen;
using std::strcpy;

int Name::number = 0;

Name::Name(const char * const f , const char * const l)
{
    setFirstName(f);
    setLastName(l);
    Name::number ++;
}
Name::~Name()
{
    delete [] firstname;
    delete [] lastname;
    number--;
}

void Name::setFirstName( const char * const first)
{
    firstname = new char[ strlen( first ) + 1 ];
    strcpy( firstname , first );
}

void Name::setLastName( const char * const last)
{
    lastname = new char[ strlen( last ) + 1 ];
    strcpy( lastname , last );
}

char *Name::getFirstName()
{
    return firstname;
}

char *Name::getLastName()
{
    return lastname;
}

ostream &operator<<( ostream &output , const Name &m )
{
    output <<"Welcome to GradeBood System" <<'\n'<<"Number is: "<<setw(2)<<left<< m.number << '\t'<<"Name is: " << m.firstname << " " << m.lastname;
    return output;
}

istream &operator>>( istream &input , Name &n )
{
    input >> setw(25) >>  n.getFirstName() >> n.getLastName();
    return input;
}


_____________________________________________________________________________________________________________________________________________

//name.h
//name class definition

#ifndef NAME_H
#define NAME_H

#include<iostream>
using std::ostream;
using std::istream;

#include<string>
using std::string;

class Name
{
    friend ostream &operator<<( ostream & , const Name & );
    friend istream &operator>>( istream & , Name & );

public:
    Name(const char * const = "",const char * const = "");
    ~Name();
    void setFirstName(const char * const);
    char *getFirstName();
    void setLastName( const char * const);
    char *getLastName();
    int getNumber(){return number;}

private:
    char *firstname;
    char *lastname;
    static int number;
};
#endif
_____________________________________________________________________________________________________________________________________________

#include "name.h"

#include <iostream>
using std::cout;
using std::cin;

#include <string>
using std::string;


int main()
{
    char *first = "";
    char *last = "";

    cout<< "Please enter the frist name or enter \"end\" to exit"<<'\n';
    cin >> first;
    cout << "Please enter the last name or enter \"end\" to exit"<<'\n';
    cin >> last;

    Name student(first , last);
    cout << student;
    cout<<'\n'<<"please inter the first name and the last of a new student:"<<'\n';
    cin >> student;
    cout << student;

    return 0;
}

1>------ 已启动生成: 项目: GradeBook, 配置: Debug Win32 ------
1>正在编译...
1>name.cpp
1>.\name.cpp(40) : warning C4996: “strcpy”被声明为否决的
1>        E:\公用软件\学习软件\Microsoft Visual Studio 8\VC\include\string.h(73) : 参见“strcpy”的声明
1>        消息:“This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_DEPRECATE. See online help for details.”
1>.\name.cpp(46) : warning C4996: “strcpy”被声明为否决的
1>        E:\公用软件\学习软件\Microsoft Visual Studio 8\VC\include\string.h(73) : 参见“strcpy”的声明
1>        消息:“This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_DEPRECATE. See online help for details.”
1>正在链接...
1>正在嵌入清单...
1>生成日志保存在“file://c:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\Projects\GradeBook\GradeBook\Debug\BuildLog.htm”
1>GradeBook - 0 个错误,2 个警告

运行的时候,一输入就出错。 。高手帮帮忙。。怎么回事,该怎么改,高手帮帮忙,感激不尽!!!!!
2008-01-05 13:48
快速回复:高手来看下
数据加载中...
 
   



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

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