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

多文件组织编译出错

glasslip 发布于 2016-06-01 21:37, 5005 次点击
我用的是visual 2008编写程序的题目是这样的新建3个文件,然后分成三块部分编写(具体看程序好了)定义三角形类计算周长和面积程序如下:
文件ex2-2.h
class triangle
{
private:
    int x,y,z;
public:
    triangle(int a,int b,int c){x=a,y=b,z=c;}
    int circumference();
    double mj();
    void print();
};
---------------------------------------------------
文件ex2-2-2.cpp
#include "stdafx.h"
#include<math.h>
#include"ex2-2.h"
int triangle::circumference()
{
    int cc;
    cc=x+y+z;
    return cc;
}
double triangle::mj()
{
    double s;
    double p;
    double t;
    p=(x+y+z)/3;
    t=p*(p-x)*(p-y)*(p-z);
    s=sqrt(t);
    return s;
}
void triangle::print()
{
    cout<<"三角形的周长="<<circumference()<<endl<<"三角形的面积="<<mj()<<endl;
}
-------------------------------------------
文件ex2-2-1.cpp
// ex2-2-1.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include<iostream>
using namespace std;
#include"ex2-2-2.cpp"
void main()
{
    int a,b,c;
    cin>>a>>b>>c;
    triangle A(a,b,c);
    A.circumference();
    A.mj();
    A.print();
}
然后最后生成解决方案的时候还是出错了
ex2-2-2.cpp
1>d:\visual2008作业练习文件\ex2-2-1\ex2-2-1\ex2-2-2.cpp(22) : error C2065: “cout”: 未声明的标识符
1>d:\visual2008作业练习文件\ex2-2-1\ex2-2-1\ex2-2-2.cpp(22) : error C2065: “endl”: 未声明的标识符
1>d:\visual2008作业练习文件\ex2-2-1\ex2-2-1\ex2-2-2.cpp(22) : error C2065: “endl”: 未声明的标识符
   
7 回复
#2
glasslip2016-06-01 21:44
之前其实也遇到过这样的问题但有些题目又没有所以现在很纠结
#3
alice_usnet2016-06-01 22:45
void triangle::print()
{
    std::cout<<"三角形的周长="<<circumference()<<std::endl<<"三角形的面积="<<mj()<<std::endl;
}
#4
glasslip2016-06-06 08:38
回复 楼主 glasslip
那样没有用,之前试过
#5
glasslip2016-06-06 08:39
回复 3楼 alice_usnet
那样没有用之前试过
#6
alice_usnet2016-06-06 23:06
程序代码:
#include "stdafx.h"
#include<iostream>
using namespace std;

void main()
{
    int a,b,c;
    cin>>a>>b>>c;
    triangle A(a,b,c);
    A.circumference();
    A.mj();
    A.print();
}
#7
zhangyoung2016-06-07 15:31
回复 6楼 alice_usnet
在文件ex2-2-2.cpp 加 #include<iostream>

std::cout
#8
zhangyoung2016-06-07 15:32
在文件ex2-2-2.cpp 加 #include<iostream>

std::cout
1