0

What is the correct way to include files

#include "../myDirecoty/myFile.h"

or

#include  "..\myDirecoty\myFile.h"

the difference is the direction of "/" or "\".

lital maatuk
  • 5,921
  • 20
  • 57
  • 79

5 Answers5

2

This is the correct way:

#include "../myDirecoty/myFile.h"
trojanfoe
  • 120,358
  • 21
  • 212
  • 242
1

There is no difference, but the first form is more "clear" because sometime people thinks to \ as an escaping character in string (but include path are not strings)

Loghorn
  • 2,729
  • 17
  • 22
  • 3
    There is a difference: the backslash being a path separator on Windows is a perfectly legal character in a UNIX filename (Mac OS X is also a UNIX, BTW). So the later will create a file-not-found error on all systems, except Windows and DOS. – DarkDust Feb 08 '11 at 15:37
  • @DarkDust: You are right... I'm too used to work on Windows and most of time I forgot unix :-( – Loghorn Feb 08 '11 at 15:59
0

normal slashes "/", best compatible

programmersbook
  • 3,914
  • 1
  • 20
  • 13
0

From what I've seen looking through the code on my computer, you should use forward slashes ('/').

Eric Finn
  • 8,629
  • 3
  • 33
  • 42
0

The backslash \ is used on Windows and DOS, while the slash / is used on all UNIX/POSIX compatible systems (like Linux and Mac OS X). So the later can produce a file-not-found error on non-Windows systems. AFAIK all Windows compiler do support the slash /, so this is one to use.

Edit: See also this SO question.

Community
  • 1
  • 1
DarkDust
  • 90,870
  • 19
  • 190
  • 224