C++头文件(No such file or directory)

版本:Visual C++ 6.0(SP6)
过程:
1 新建Win32 Console Application c:\1104(保存路径) 1104(文件名)
2 新建C/C++ Header File c:\1104(保存路径) 1104(文件名)
3 新建C++ Source File c:\1104(保存路径) 1104(文件名)
4 附2 3的程序代码(见后附)

编译提示信息
--------------------Configuration: 1104 - Win32 Debug--------------------
Compiling...
1104.cpp
c:\program files\microsoft visual studio\myprojects\1104\1104.cpp(5) : fatal error C1083: Cannot open include file: 'shape.h': No such file or directory
执行 cl.exe 时出错.

1104.obj - 1 error(s), 0 warning(s)
---请问这是怎么回事呢?错出在哪里呢?
盼赐教,谢谢

附:
4 附2 3程序代码
//***************
//* shape.h *
//***************
#include "math.h"
const double pi=3.14159265358;
struct cirle
{
double r;
};
struct square
{
double a;
};
struct rectangle
{
double a,b;
};
struct triangle
{
double a,b,c,alpha,beta,gamma;
};
double rerimeter_of_circle(double r)
{
return 2*pi*r;
};
double area_of_circle(double r)
{
return pi*r*r;
};
double perimer_of_square(double a)
{
return 4*a;
};
double area_of_square(double a)
{
return a*a;
};
double perimeter_of_rectangle(double a,double b)
{
return 2*(a+b);
};
double area_of_rectangle(double a,double b)
{
return a*b;
};
double perimeter_of_triangle(double a,double b,double c)
{
return a+b+c;
};
double area_of_triangle(double a,double b,double gamma)
{
return sin(gamma/180*pi)*a*b/2;
};
//*************
//* main.cpp *
//*************
#include "iostream.h"
#include "shape.h"
int main()
{
circle c={2};
square s={1};
rectangle r={2,3};
triangle t={3,4,5,36.86989,53.13011,90};
cout <<"Perimeter of circle " <<perimeter_of_circle(c.r) <<endl;
cout <<"Area of square "<<area_of_square(s.a) <<endl;
cout <<"Perimeter of rectangle " <<pertimeter_of_rectangle(r.a,r.b) <<endl;
cout <<"Area of triangle " <<area_of_triangle(t.b,t.c,t.alpha) <<endl;
return 0;
}
存储路径应为:
c:\program files\microsoft visual studio\myprojects
(提问的时候偷懒造成的,见笑)
1105 09:30
谢谢各位的回答。
但是我还是没有发现我的错误所在,有没有朋友能够给个可执行修改稿呢?
1 3137333
使用了工程。
创造的第一个文件就是个工程。
2 windseeker2007
你认为应该怎么修改呢?
3 禾勹彐心
在我的书上关于头文件的规则讲得很少,需要你具体的指导

1107
4
致leilwang:
谢谢你的答案。但是我还是很遗憾的告诉你,我把你的程序代码复制-粘贴后进行编译,出现同样的错误提示---Cannot open include file: 'shape.h': No such file or directory
执行 cl.exe 时出错.
如果我们确定在语法格式、算法思路上不存在问题,那问题又是出在哪里呢?

//shape.h

#ifndef SHAPE_H_INCLUDED

#define SHAPE_H_INCLUDED

#include "math.h"

const double pi = 3.14159265358;

double perimeter_of_rectangle(double a,double b);

struct rectangle

{

double a, b;

};

double perimeter_of_rectangle(double a,double b)

{

return 2*(a+b);

};

#endif // SHAPE_H_INCLUDED

//main.cpp

#include <iostream>

#include "shape.h"

int main()
{
using namespace std;

struct rectangle r =

{

2, 3

};

cout << "Perimeter of rectangle " << perimeter_of_rectangle(r.a, r.b) << endl;

return 0;

}

扩展资料

头文件一般由四部分内容组成:

(1)头文件开头处的版权和版本声明;

(2)预处理块;

(3)inline函数的定义;

(4)函数和类结构声明等。

在头文件中,用 ifndef/define/endif结构产生预处理块,用 #include 格式来引用库的头文件。

#ifndef GRAPHICS_H//作用:防止graphics.h被重复引用

#define GRAPHICS_H

#include<....>//引用标准库的头文件

...

#include"..."//引用非标准库的头文件

...

void Function1(...);//全局函数声明

...

inline();//inline函数的定义

...

classBox//作用:类结构声明

{

...

};

#endif

参考资料:百度百科 头文件

温馨提示:答案为网友推荐,仅供参考
第1个回答  2008-11-11
不知道你上面的代码是不是从编辑器拷出来的,如果是,那你的程序可就惨了。
我先说下我的操作过程。
1 new Win32 Console Application
2 new C/C++ Header File
所有的路径都按默认,只是写了文件名(shape.h )
没有 “3 新建C++ Source File c:\1104(保存路径) 1104(文件名)”,因为我刚始创建的不是一个空的工程,系统会自动给我生成一个 1104.cpp。
我想你的错误应该就在这里,你创建的应该是一个空工程。下面是当你创建空工程时的具体做法:
你在vc里要有一定要有一句#include “stdafx.h”(用vc的都知道)。
所以你就要在你工程的目录里 添加两个文件 一个是 stdafx.h,另一个是stdafx.cpp这样就好了,如果有必要你还要在你的工程里加入这两个文件。
在右边的FileView(文件视图)里的Source File 上右击 选择“添加文件到目录”在弹出的对话框里选stdafx.cpp,同样在Header File 上右击 选择“添加文件到目录”在弹出的对话框里选stdafx.h。OK
比较麻烦,所以一般不要创建空工程。

下面分析代码:
//***************
//* shape.h *
//***************
#include "math.h" //首先,没有头文件卫士 >?<
const double pi=3.14159265358;
struct cirle
{
double r;
};
struct square
{
double a;
};
struct rectangle
{
double a,b;
};
struct triangle
{
double a,b,c,alpha,beta,gamma;
};
double rerimeter_of_circle(double r)//是perimeter_of_circle 吧?!
{
return 2*pi*r;
};///////////////////////////// ErrorA.不明白函数体后面为什么要加分号(;)
double area_of_circle(double r)
{
return pi*r*r;
}; ////////////////////////////////////同ErrorA
double perimer_of_square(double a)//看函数名拼写正确吗?是不是 perimeter_of_tsquare??
{
return 4*a;
}; ////////////////////////////////////同ErrorA
double area_of_square(double a)
{
return a*a;
}; ////////////////////////////////////同ErrorA
double perimeter_of_rectangle(double a,double b)
{
return 2*(a+b);
}; ////////////////////////////////////同ErrorA
double area_of_rectangle(double a,double b)
{
return a*b;
}; ////////////////////////////////////同ErrorA
double perimeter_of_triangle(double a,double b,double c)
{
return a+b+c;
}; ////////////////////////////////////同ErrorA
double area_of_triangle(double a,double b,double gamma)
{
return sin(gamma/180*pi)*a*b/2;
}; ////////////////////////////////////同ErrorA
下面是主函数:
//*************
//* main.cpp *
//*************
#include "iostream.h" //是否忘了#include “stdafx.h”
#include "shape.h"
int main()
{
circle c={2};
square s={1};
rectangle r={2,3};
triangle t={3,4,5,36.86989,53.13011,90};
cout <<"Perimeter of circle " <<perimeter_of_circle(c.r) <<endl;
cout <<"Area of square "<<area_of_square(s.a) <<endl;
cout <<"Perimeter of rectangle " <<pertimeter_of_rectangle(r.a,r.b) <<endl; //函数名写错了吧?perimeter_of_rectangle???!!
cout <<"Area of triangle " <<area_of_triangle(t.b,t.c,t.alpha) <<endl;
return 0;
}

按照提示改正后应该就可以正常运行了。本回答被提问者采纳
第2个回答  2015-08-07
总提示找不到头文件(ndk-build error: string: No such file or directory) :
首先检查有没有Application.mk文件,如果没有在所在目录下面新建个Application.mk文件,在里面添加APP_STL := gnustl_static就可以找到标准库了。
第3个回答  2019-01-04
//shape.h
#ifndef
SHAPE_H_INCLUDED
#define
SHAPE_H_INCLUDED
#include
"math.h"
const
double
pi
=
3.14159265358;
double
perimeter_of_rectangle(double
a,double
b);
struct
rectangle
{
double
a,
b;
};
double
perimeter_of_rectangle(double
a,double
b)
{
return
2*(a+b);
};
#endif
//
SHAPE_H_INCLUDED
//main.cpp
#include
<iostream>
#include
"shape.h"
int
main()
{
using
namespace
std;
struct
rectangle
r
=
{
2,
3
};
cout
<<
"Perimeter
of
rectangle
"
<<
perimeter_of_rectangle(r.a,
r.b)
<<
endl;
return
0;
}
扩展资料
头文件一般由四部分内容组成:
(1)头文件开头处的版权和版本声明;
(2)预处理块;
(3)inline函数的定义;
(4)函数和类结构声明等。
在头文件中,用
ifndef/define/endif结构产生预处理块,用
#include
格式来引用库的头文件。
#ifndef GRAPHICS_H//作用:防止graphics.h被重复引用
#define GRAPHICS_H
#include<....>//引用标准库的头文件...
#include"..."//引用非标准库的头文件
...void Function1(...);//全局函数声明
...inline();//inline函数的定义
...classBox//作用:类结构声明
{...
};#endif
参考资料:百度百科
头文件
第4个回答  2008-11-04
函数不要在头文件中定义,而且你的函数都加了;符号,在源文件中对结构变量(结构体或类)中的函数实现一般定义在main()函数之外。

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网