[c++] How to compile C++ under Ubuntu Linux?

To compile source.cpp, run

g++ source.cpp

This command will compile source.cpp to file a.out in the same directory. To run the compiled file, run

./a.out

If you compile another source file, with g++ source2.cpp, the new compiled file a.out will overwrite the a.out generated with source.cpp

If you want to compile source.cpp to a specific file, say compiledfile, run

g++ source.cpp -o compiledfile

or

g++ -o compiledfile source.cpp

This will create the compiledfile which is the compiled binary file. to run the compiledfile, run

./compiledfile

If g++ is not in your $PATH, replace g++ with /usr/bin/g++.