免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12下一页
最近访问板块 发新帖
查看: 4648 | 回复: 14
打印 上一主题 下一主题

为何.cpp中不能包含.h文件!!!! [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2004-02-27 11:19 |只看该作者 |倒序浏览
coordin.h
--------------------------------------
#ifndef  COORDIN_H_
#define COORDIN_H_
struct polar{
  double distance;
  double angle;
};

struct rect{
  double x;
  double y;
};
polar rect_to_polar(rect xypos);
void  show_polar(polar dapos);
#endif

-------------------------------------------------
file1.cpp
-------------------------------------------------
#include <iostream>;
#include "coordin.h"
int main(){
    rect rplace;
    polar pplace;
    cout<<"Enter the x and y values:";
    while(cin>;>;rplace.x>;>;rplace.y){
        pplace=rect_to_polar(rplace);
        show_polar(pplace);
        cout<<"Next two numbers (q to quit):";
    }
     cout<<"Bye!\n";
     return 0;
}
-------------------------------------------------
file2.cpp
-------------------------------------------------
#include <iostream>;
#include <cmath>;
#include "coordin.h"
using namespace std;
polar rect_to_polar(rect xypos){
   polar answer;
   answer.distance=sqrt(xypos.x*xypos.x+xypos.y*xypos.y);
   answer.angle=atan2(xypos.y,xypos.x);
   return answer;
}
void show_polar(polar dapos){
   const double Rad_to_deg=57.29577951;
   cout<<"distance="<<dapos.distance;
   cout<<",angle="<<dapos.angle*Rad_to_deg;
   cout<<"degrees\n";
}
//调试出错,是不是vc++6.0 不支持,我是新手,还请高手指教!!
--------------------Configuration: file1 - Win32 Debug--------------------
Compiling...
file1.cpp
c:\program files\microsoft visual studio\vc98\include\iostream(16) : fatal error C1001: INTERNAL COMPILER ERROR
        (compiler file 'msc1.cpp', line 1786)
         Please choose the Technical Support command on the Visual C++
         Help menu, or open the Technical Support help file for more information
Error executing cl.exe.

file1.obj - 1 error(s), 0 warning(s)

论坛徽章:
0
2 [报告]
发表于 2004-02-27 11:32 |只看该作者

为何.cpp中不能包含.h文件!!!!

不是.cpp中不能包含.h文件问题,好好检查一下你的代码

论坛徽章:
1
荣誉版主
日期:2011-11-23 16:44:17
3 [报告]
发表于 2004-02-27 11:37 |只看该作者

为何.cpp中不能包含.h文件!!!!

while(cin>;>;rplace.x>;>;rplace.y){
对这一句很不理解。
为什么要这样?

论坛徽章:
0
4 [报告]
发表于 2004-02-27 11:45 |只看该作者

为何.cpp中不能包含.h文件!!!!

原帖由 "lenovo" 发表:
while(cin>;>;rplace.x>;>;rplace.y){
对这一句很不理解。
为什么要这样?

接受来看键盘的输入啊,如果是字符就退出!!

论坛徽章:
0
5 [报告]
发表于 2004-02-27 11:46 |只看该作者

为何.cpp中不能包含.h文件!!!!

[quote]原帖由 "arenxl"]不是.cpp中不能包含.h文件问题,好好检查一下你的代码[/quote 发表:

连接编译出错,但我找不出错在哪了,谁能介绍一下vc++环境的连接编译的步骤,不胜感激!!!

论坛徽章:
1
荣誉版主
日期:2011-11-23 16:44:17
6 [报告]
发表于 2004-02-27 11:53 |只看该作者

为何.cpp中不能包含.h文件!!!!

原帖由 "cqrjc32" 发表:

接受来看键盘的输入啊,如果是字符就退出!!

可是你这样做也不能保证它们正确的输入。
这三个文件是不是在一个工程里面?

论坛徽章:
0
7 [报告]
发表于 2004-02-27 14:22 |只看该作者

为何.cpp中不能包含.h文件!!!!

在我的vc6上试验了一下,没有问题的,不过file1.cpp中少了
using namespace std;
加上后就好啦
,没有出现楼主说的问题,看来是楼主工程建立得不对造成得吧。应该选择
win32 console application-->;工程名-->;选择empty project
然后把.h和.cpp文件加入:fileview->;source file /header file右键加入新文件就可以了.

论坛徽章:
0
8 [报告]
发表于 2004-02-27 15:28 |只看该作者

为何.cpp中不能包含.h文件!!!!

原帖由 "li2002" 发表:
在我的vc6上试验了一下,没有问题的,不过file1.cpp中少了
using namespace std;
加上后就好啦
,没有出现楼主说的问题,看来是楼主工程建立得不对造成得吧。应该选择
win32 console application-->;工程名..........



谢谢li2002老大的指点,程序能运行了,
VC中包含应使用
#include <iostream.h>;
而不能用
#include <iostream>;
好像C++Builder中两种方式就没问题!!!!

论坛徽章:
1
荣誉版主
日期:2011-11-23 16:44:17
9 [报告]
发表于 2004-02-27 15:42 |只看该作者

为何.cpp中不能包含.h文件!!!!

这样用:

  1. #include <iostream>;
  2. using namespace std;
复制代码

最好不要用#include <iostream.h>;

论坛徽章:
0
10 [报告]
发表于 2004-02-27 16:13 |只看该作者

为何.cpp中不能包含.h文件!!!!

vc也没有问题的
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP