Thread: How to use files in other directory?

  1. #1
    Registered User
    Join Date
    Sep 2006
    Posts
    52

    How to use files in other directory?

    I wrote codes for some file that were ".h" files.And now I want to use them in other programs..how do I have to declare to use them?please help me..thanks very much....

  2. #2
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,079
    Code:
    #include "myLibrary.h"
    
    // or if they're in a sub directory...
    
    #include "directory/myLib.h"
    Sent from my iPadŽ

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Use the -I command line option (pretty universal as far as command line flags go)

    If you have
    #include <myheader.h>

    Then
    g++ -I/path/to/headers prog.cpp

    would look to see if /path/to/headers/myheader.h existed, and if it does it would be included.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #4
    Registered User
    Join Date
    Sep 2006
    Posts
    52
    Example I have a "temp.h" file in directory "C:\School\programs\temp.h" and program that I want to use this file is in "D:\example\usetemp.cpp".How do I have to declare to use "temp.h"?....

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    I already said how.

    If you want detailed instructions for your specific compiler / IDE, you're going to have to say which one it is.

    Start in project - > settings -> compiler sort of place and then look for include paths.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Reading .dat files from a folder in current directory...
    By porsche911nfs in forum C++ Programming
    Replies: 7
    Last Post: 04-04-2009, 09:52 PM
  2. All files in a directory
    By cloudy in forum Linux Programming
    Replies: 1
    Last Post: 06-09-2008, 01:50 AM
  3. Couple errors please help :-D
    By JJJIrish05 in forum C Programming
    Replies: 9
    Last Post: 03-06-2008, 02:54 AM
  4. Listing files in a directory.
    By Devil Panther in forum C++ Programming
    Replies: 5
    Last Post: 11-04-2006, 09:39 PM
  5. Reading files in a directory
    By roktsyntst in forum Windows Programming
    Replies: 5
    Last Post: 02-07-2003, 10:04 AM