作者ja77 (LaTex)
看板EE_DSnP
标题Re: [问题]#include的error:No such file or direc …
时间Tue Oct 21 00:20:37 2008
Somethings about the "include" command which is one
of the preprocessor directives:
1. Two formats of the #include
#include 指令可以读入你所指定的档案内容,通常有两种形式
#include <somefile> (C++) or #include <somefile.h> (C)
#include "myfile.h"
如果档名以(< >)括起来,表示要读入的档案是个专案表头or标准表头档,
那麽搜寻路径会是一个预先特定的目录;如果档名以(" ")括起来,表示要
读入的档案是程式员提供的表头档,那个搜寻路径应该会从工作目录or目
前所在的目录开始搜寻。
2. The difference between including .h and including .cpp
其实问题应该要问include header file(表头档)和include source file
(程式原始码档)的不同,因为表头档的副档名会随着C++ compiler的不同
而有所不同(这也就是为什麽C++标准表头档决定不使用副档名的原因之一)
,通常会放在表头档的东西有extern object宣告、函式宣告和inline函式
定义,凡是必须使用或定义object或函式的程式原始码档,都应该含入这个
表头档,所以程式原始码档通常是用来定义object或函式,当你include程
式原始码档就有可能会发生重复定义相同的object或函式的错误,但是如果
你include表头档只有一些宣告,重复宣告是没有关系的。
※ 引述《wintercobra (wintercobra)》之铭言:
: 我开了一个专案,main.cpp和HW3-2-upp.cpp都放在同一个资料夹下
: //in main.cpp
: #include <cstdlib>
: #include <iostream>
: #include <time.h>
: #include <HW3-2-upp.h>
: using namespace std;
: int main(int argc, char *argv[])
: {
: .........
: }
: 编译main的时候他说HW3-2-upp.h.No such file or directory.
: 把.h改成.cpp也还是一样
: 请问是为什麽呢?
: 喔还有include的时候.h和.cpp的差别在哪我还是不太清楚
: 可以麻烦再说明一下吗?
: 谢谢~~
--
以上是小的浅见...不知道有没有错,哈!?
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 140.112.171.138
1F:推 wintercobra:谢啦~ 不过,重覆宣告没有关系? 不是要用#ifndef吗? 10/22 08:46