注册 登录
编程论坛 C++教室

问个编译器问题

shizhusz110 发布于 2007-03-13 18:29, 856 次点击

我写程序为什么不能包含我定义文件:
如:
#ifndef DATE_H
#define DATE_H
class date
{int mo,da;
public:
date(int i,int j)
{mo=i;da=j;
}
void display()const
{cout<<mo<<'-'<<endl;
}
};
#endif

#include<iostream.h>
#include "date.h"《编译器说这里有错》
int main(int argc,char *argv[])
{date t(12,31);
t.display();
return 0;
}
我的不能编译编译,运行它,才学c++还好多不知道,谢谢批评~~~~~
谢谢回复

14 回复
#2
shizhusz1102007-03-13 18:31
我用的是c-free3.5
#3
yuyunliuhen2007-03-13 19:11

#include<iostream>
using namespace std;

#ifndef DATE_H


#define DATE_H
class date
{int mo,da;
public:
date(int i,int j)
{
mo=i;
da=j;
}
void display() const
{
cout<<mo<<"-"<<endl;
}
};
#endif


int main(int argc,char *argv[])
{
date t(12,31);

t.display();
return 0;
}
注释要用//


也可以这样,把她做两个文件*.h,*.cpp.编译时放在同一个文件下
#include<iostream>
using namespace std;

#ifndef DATE_H


#define DATE_H
class date
{int mo,da;
public:
date(int i,int j)
{
mo=i;
da=j;
}
void display() const
{
cout<<mo<<"-"<<endl;
}
};
#endif //保存文件名为data.h;



#include<iostream>
#include"data.h"
using namespace std;

int main(int argc,char *argv[])
{
date t(12,31);

t.display();
return 0;
}

[此贴子已经被作者于2007-3-13 19:22:57编辑过]

#4
shizhusz1102007-03-13 20:56
xie谢谢版主~~~~~我一定好好记住
#5
shizhusz1102007-03-13 21:04
还问一下,我的编译器怎么,对2的一种方法不行??
#6
yuyunliuhen2007-03-13 21:29
我用VC++ 测试过了,可以的.

你用的什么编译器,错误提示是什么呢?
可能是你文件的保存方式不对吧,头文件*.h,*.pp.文件要在一个文件夹下,编译*.cpp文件就好了.
#7
shizhusz1102007-03-14 09:57

谢谢
我的是C-free3.5
我也想用vc++可是我在运行的时候,说不可以执行??我也不知道怎么搞??
谢谢版主知道怎么做不?帮帮忙~~~

#8
shizhusz1102007-03-14 10:00
哦我没说清楚~我的vc++编译没错就是说:不可以执行
#9
yuyunliuhen2007-03-14 21:36
以下是引用shizhusz110在2007-3-14 9:57:32的发言:

谢谢
我的是C-free3.5
我也想用vc++可是我在运行的时候,说不可以执行??我也不知道怎么搞??
谢谢版主知道怎么做不?帮帮忙~~~

不会出现这样的问题吧,我用VS2005,和VC++6.0都编译过了,且没有出现你说的那个情况呀

#10
shizhusz1102007-03-14 21:44

谢谢斑竹!!你的是没问题??我的编译起有问题??
我的vc不能执行:出现个对话框,显示:”无法执行“的字
谢谢
那在vs2005怎么做c++???我搞了好就都没做好,谢谢

#11
yuyunliuhen2007-03-14 21:56

VS2005包含VC++2005啊,是VC++6.0以后的版本,支持新的C++标准,VC++6.0存在的一些BUG也修正了,界面看起来比较舒服,可以考虑用一下的

#12
shizhusz1102007-03-15 10:01
xiexie!我正在下
#13
shizhusz1102007-03-15 10:08
还问一下有没有vc2005的教程!!!谢谢
我也不知道怎么在里面加c++所以介绍一本教程,以后小事就不麻烦您们了!!
谢谢斑竹的帮忙!!!
#14
yuyunliuhen2007-03-19 21:19

http://tech.163.com/05/0321/09/1FC0JC9C00091589_3.html
毕竟VC++2005出来的时间不是很长,没有发现成套的教程,只有自己慢慢摸索了,最好下个中文版的,它是VC++6.0以后的版本,会用VC++6.0的话,这个也应该没问题的.

#15
shizhusz1102007-03-20 16:15
谢谢斑竹!!!
1