chipp
chipp

Reputation: 63

C++ library path inclusion

i found C++ libraries could be included this way:

#include "..\example.h"
#include ".\another_example.h"

what is the dots used for?

Upvotes: 3

Views: 606

Answers (5)

sasha.sochka
sasha.sochka

Reputation: 14715

Double dots stand for the parent directory of the currently entered path. Single dot stands for the currently entered path on the left side of a dot and is used to show that you want a relative path.

A relative path is a path relative to the working directory of the user or application, so the full absolute path will not have to be given.

If you start your path with / (on *nix systems) or DRIVELETTER: (on Windows, e.g. D:) then the path is absolute. If you don't - the path is relative. If path is relative - it automatically prepends the directory of your file to the path entered.

Example:

"dir/././../dir/.." is the directory which contains the original file. The reductions are:

dir/././../dir/.. -> dir/./../dir/.. -> dir/../dir/.. -> /dir/.. -> . -> working directory. We removed ./ because it's alias to the current directory. We removed /dir/.. because we enter a directory with dir and get back with ..

One of the most often used features of ./ (but in the context of a shell, e.g. bash) - it forces to use a relative path instead of calling an executable program in the $PATH variable. For example if you type ls in terminal on *nix it will list the files in the working directory. If you type ./ls it will run executable with the name ls in the current working directory and execute whatever this program does.

You can read more about path separators in this article on wikipedia

Upvotes: 2

πάντα ῥεῖ
πάντα ῥεῖ

Reputation: 1

They are to indicate the included file paths' are relative to the including file's actual path.

. points to the including file's actual directory
.. points to the including file's actual directories' parent diretory

Upvotes: 6

Shumail
Shumail

Reputation: 3143

one dot . is for file's directory

2 dots .. are for file's parent directory.

Upvotes: 0

bstamour
bstamour

Reputation: 7776

Two dots means one directory higher than the current one. For example, if you are in the directory C:\some\directory", "..\" would be "C:\some".

A single dot refers to the current directory. So using the previous example, ".\" would mean "C:\some\directory".

Upvotes: 0

morze
morze

Reputation: 1

One dot is your current directory and two dots is your parent directory.

Upvotes: 0

Related Questions