c++编译一个连接问题

来源:百度知道 编辑:UC知道 时间:2024/05/26 00:41:28
#include<iostream.h>
#include<stdlib.h>
#include "stdlib.h"

int main()
{
int m;
int j,i,k,d;
double n;
cout<<"\n请输入一个大与1的正数m";
cin>>m;
d=GetRandomNumber(m);
cout<<"输入一个m返回的是";
cout<<d<<endl;
cout<<"\n请输入两个整数i和j,i不等于j,并且j>i";
cin>>i>>j;
k=GetRandomNumber(i,j);
cout<<i<<"\n和"<<"\n之间产生的随机数为"<<k<<endl;
n=GetRandomNumber();
cout<<"\n返回一个0.000-1.000之间的随机数为";
cout.setf(ios::fixed|ios::showpoint);
cout.precision(3);
cout<<n<<endl;

return 0;
}

#include "hanshu.cpp"

上面是主函数
下面是我的文件
hanshu.cpp
#include "stdlib.h"
#include<iostream.h>
#include<stdlib.h>

int GetRand

#include "hanshu.cpp"改为#include "hanshu.h"
函数声明和定义放在.h 和.cpp文件中即可;
或者保证hanshu.cpp只被编译一次
#ifndef HANSHU
#define HANSHU
hanshu.cpp的内容
#endif

函数重定义了。
你把包含
int GetRandomNumber(int);
int GetRandomNumber(int,int);
double GetRandomNumber();
的文件删掉。直接包含那个定义的文件就可以了“hanshu.cpp"。