-4
g++ main.cpp main
./main

why do we use ./ sign? why can't we type "run main" ? Who made this convention? is it purely historical? Also, can we change this ./ to run main forever? I suppose you can do it with bash script?

ERJAN
  • 23,696
  • 23
  • 72
  • 146
  • 1
    ./filename is the convential way of telling the computer to look at a file. Without the "./" it would interpret filename as an invalid command. Therefore, instead of saying "run main", what if we have multiple compiled executables and want to run one? What if we don't want to type "run" a billion times in our lifetimes of testing and developing? The simplest solution, type the bare minimum of the executable alone. – Chris Zhang Jan 22 '14 at 04:57
  • @soon I'm not sure this is an exact duplicate. That question talks about why, to run commands, you need to use dot-slash. I think that the OP isn't aware that `./main` is a command like any other command and therefore is subject to the same set of rules as any other command, so a different set of answers might be inorder. – templatetypedef Jan 22 '14 at 04:58
  • 1
    "Without the "./" it would interpret filename as an invalid command." - actually, it would search for filename in the PATH, and, if not found, say something along the lines of "command not found". – Frank Osterfeld Jan 22 '14 at 05:02

1 Answers1

4

It has nothing to do with C++, it's your command shell. It's simply the way of telling it that the file exists in the current directory.

Mark Ransom
  • 299,747
  • 42
  • 398
  • 622