Compiling C++

mjia

Registered
I'm trying to use Mac OS X to write simple C++ programs, but I can't seem to get the compiler to work. At school, I use a Sun UNIX terminal and compile my programs though the shell using the "g++" command, but it doesn't seem to work properly on my Mac, even though I have installed BSD and the Developer Tools. Here is the simple code I tried to compile:

#include <iostream>

int main() {
std::cout << "hello";
}

Then, in the terminal I entered:

g++ test.cpp -o test

It generated a file "test", but it does nothing.
 
This is a simple one, execute your program like this:

./test

The current directory is not in your PATH by default. There is a system utility named test which is getting executed instead of your program. The ./ tells the shell to execute the program test that is in the current directory
 
Back
Top