Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > #include files from another directory

Reply
Thread Tools

#include files from another directory

 
 
Christopher
Guest
Posts: n/a
 
      01-15-2004
What is the syntax for including files from another directory? In my case I
want to include a file called "error.h" which lies in a directory called
"support" which is a directory inside the (project/solution/source or
whatever you may call it) directory.

it looks like this (hope the ascii comes out)
dir engine_x
.....dir support
..............file error.h
..............file error.cpp
.....file main.cpp

Thanx,
Christopher



 
Reply With Quote
 
 
 
 
Donovan Rebbechi
Guest
Posts: n/a
 
      01-15-2004
In article <rnpNb.58466$(E-Mail Removed)>, Christopher wrote:
> What is the syntax for including files from another directory? In my case I
> want to include a file called "error.h" which lies in a directory called
> "support" which is a directory inside the (project/solution/source or
> whatever you may call it) directory.


Your compiler and/or development environment should allow you to add
directories to the search path. Specify the header using angle brackets
<errno.h> and compile with the right flags.

Cheers,
--
Donovan Rebbechi
http://pegasus.rutgers.edu/~elflord/
 
Reply With Quote
 
 
 
 
Jacques Labuschagne
Guest
Posts: n/a
 
      01-15-2004
Christopher wrote:
> What is the syntax for including files from another directory? In my case I
> want to include a file called "error.h" which lies in a directory called
> "support" which is a directory inside the (project/solution/source or
> whatever you may call it) directory.


#include "support/error.h"

>
> it looks like this (hope the ascii comes out)
> dir engine_x
> ....dir support
> .............file error.h
> .............file error.cpp
> ....file main.cpp
>


The standard way to draw a directory tree is

engine_x
|-- support
| |-- error.h
| `-- error.cpp
`-- main.cpp

Jacques.

 
Reply With Quote
 
David Fisher
Guest
Posts: n/a
 
      01-15-2004
"Christopher" <(E-Mail Removed)> wrote:

> What is the syntax for including files from another directory? In my case

I
> want to include a file called "error.h" which lies in a directory called
> "support" which is a directory inside the (project/solution/source or
> whatever you may call it) directory.
>
> it looks like this (hope the ascii comes out)
> dir engine_x
> ....dir support
> .............file error.h
> .............file error.cpp
> ....file main.cpp


There are a few options:

1. Your C++ compiler probably has a flag to let you specify where to look
for include files other than the current directory. For gcc the flag is
"-I"; for Visual C++ 6.0, look in Tools -> Options -> Directories.

2. You can #include a file in a relative directory, eg. #include
"engine_x/support/error.h" (assuming the current directory is the one below
engine_x). Note that all known include directories are searched, so you
could so something like adding "engine_x" to the include directory list (as
above) and then say #include "support/error.h"

3. (Never do this !) Use the absolute path name, eg. #include
"/home/users/fred/engine_x/support/error.h" This is very bad, because the
code can never be moved around or given to someone else.

BTW. If possible, it might be a good idea to rename "error.h" - it is a
common name, and it might get confusing if the wrong header is included.

David F


 
Reply With Quote
 
Howard
Guest
Posts: n/a
 
      01-15-2004

"Jacques Labuschagne" <(E-Mail Removed)> wrote in message
news:CRpNb.17268>
>
> The standard way to draw a directory tree is
>
> engine_x
> |-- support
> | |-- error.h
> | `-- error.cpp
> `-- main.cpp
>
> Jacques.


Funny...I've looked all through the C++ standard specifications, and
couldn't find that tree structure anywhere!


 
Reply With Quote
 
Jeff Schwab
Guest
Posts: n/a
 
      01-15-2004
Jacques Labuschagne wrote:
> Christopher wrote:
>
>> What is the syntax for including files from another directory? In my
>> case I
>> want to include a file called "error.h" which lies in a directory called
>> "support" which is a directory inside the (project/solution/source or
>> whatever you may call it) directory.

>
>
> #include "support/error.h"
>
>>
>> it looks like this (hope the ascii comes out)
>> dir engine_x
>> ....dir support
>> .............file error.h
>> .............file error.cpp
>> ....file main.cpp
>>

>
> The standard way to draw a directory tree is
>
> engine_x
> |-- support
> | |-- error.h
> | `-- error.cpp
> `-- main.cpp
>
> Jacques.
>


I didn't realize the standard had anything to say on the matter.

I happen to prefer this:

engine_x
|
+-support
| |
| +-error.h
| +-error.cpp
|
+-main.cpp

 
Reply With Quote
 
Jacques Labuschagne
Guest
Posts: n/a
 
      01-15-2004
Howard wrote:
> "Jacques Labuschagne" <(E-Mail Removed)> wrote in message
> news:CRpNb.17268>
>
>>The standard way to draw a directory tree is
>>
>>engine_x
>>|-- support
>>| |-- error.h
>>| `-- error.cpp
>>`-- main.cpp
>>
>>Jacques.

>
>
> Funny...I've looked all through the C++ standard specifications, and
> couldn't find that tree structure anywhere!
>
>


Ahem... Standard according to the Unix 'tree' program

Jacques

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to move directory ( with contents) to another directory. mike Java 2 03-15-2008 04:06 AM
System.IO.Directory.GetDirectories() and System.IO.Directory.GetFiles() are not returning the specified directory Nathan Sokalski ASP .Net 2 09-06-2007 03:58 PM
Directory and files names in temporary asp.net directory =?Utf-8?B?QmFzIEhlbmRyaWtz?= ASP .Net 5 01-31-2005 01:56 PM
list all css files in a directory and sub directory TJS ASP .Net 1 06-23-2004 10:49 AM



Advertisments