| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 786 人关注过本帖
标题:哪位能手帮下
取消只看楼主 加入收藏
guxinghan
Rank: 1
等 级:新手上路
帖 子:10
专家分:0
注 册:2010-10-9
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:5 
哪位能手帮下
//stdafx.h
#include <iostream>
#include<string>
#include <Emp.h>
using namespace std;

//Emp.h
using namespace std;
class CEmp  
{
public:
    CEmp();
    virtual~CEmp(){delete[] name;}
    void set_name(char *);
        void set_age(short a){age=a;};
        void set_salary(float s){salary=s;};
        void print();
        
private: char *name;
         short age;
         float salary;
}
//Emp.cpp
#include"stdafx.h"
#include "Emp.h"

CEmp::CEmp()
{
    name=0;
    age=0;
    salary=0;

}
void CEmp::set_name(char *n)
{
name=new char(strlen(n)+1);
strcpy(name,n);
}
void CEmp::print()
{
cout<<"Name:"<<name;
cout<<"Age:"<<age;
cout<<"Salary:"<<salary<<endl;
}

//text.cpp
#include "stdafx.h"


int main(int argc,char* argv[])
{
    char *name=NULL;
    short age=0;
    float salary=0;
    name=new char[30];
    CEmp emp[3];
    for(int i=0;i<3;i++)
    {
        cout<<"输入第"<<i+1<<"员工的信息"<<endl;
        cout<<"姓名:";
        cin>>name;
        cout<<"年龄:";
        cin>>age;
        cout<<"工资:";
        cin>>salary;
        emp[i].set_name(name);
        emp[i].set_age(age);
        emp[i].set_salary(salary);
        emp[i].print();
    }
    return 0;
}
错误f:\工具\visual c++6.0\msdev98\myprojects\009\stdafx.h(17) : fatal error C1083: Cannot open include file: 'Emp.h': No such file or directory
帮忙看下。为什么打不开Emp.h 头文件啊
搜索更多相关主题的帖子: 能手 
2010-10-10 21:23
guxinghan
Rank: 1
等 级:新手上路
帖 子:10
专家分:0
注 册:2010-10-9
收藏
得分:0 
stdafx.h需要放些什么头文件在里面.难道不要嘛?加个qq好不?我的976611409。
2010-10-11 13:40
guxinghan
Rank: 1
等 级:新手上路
帖 子:10
专家分:0
注 册:2010-10-9
收藏
得分:0 
具体告诉我怎么放这些文件怎么就是不行啊。汗
2010-10-11 13:54
guxinghan
Rank: 1
等 级:新手上路
帖 子:10
专家分:0
注 册:2010-10-9
收藏
得分:0 
可是改成"Emp.h"还是说不正确啊。
2010-10-11 16:25
guxinghan
Rank: 1
等 级:新手上路
帖 子:10
专家分:0
注 册:2010-10-9
收藏
得分:0 
改成:#include"Emp.h"后:
f:\工具\visual c++6.0\msdev98\myprojects\009\stdafx.h(18) : error C2143: syntax error : missing ';' before 'using'
加了;后:f:\工具\visual c++6.0\msdev98\myprojects\009\stdafx.h(17) : warning C4067: unexpected tokens following preprocessor directive - expected a newline
f:\工具\visual c++6.0\msdev98\myprojects\009\stdafx.h(18) : error C2143: syntax error : missing ';' before 'using'
执行 cl.exe 时出错.帮忙下谢谢了
2010-10-11 18:02
guxinghan
Rank: 1
等 级:新手上路
帖 子:10
专家分:0
注 册:2010-10-9
收藏
得分:0 
为什么要加分号啊。加了试了也不行。我是这样操作的。首先点击插入,插入类,命名CEmp,在Emp.h头文件里编入上面的那些程序。接着在Emp.cpp写入程序。再在stdafx.h头文件中加入一些需要包含的头文件。再text.cpp写入上述程序。我是按照书本上一字不漏抄下来的。怎么就是运行不正确。是 哪里操作不正确吗?帮忙下。谢谢了。我用的是visual c++ 6.0版本编写的。
2010-10-12 15:37
快速回复:哪位能手帮下
数据加载中...
 
   



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

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