You sure can.
You have two options for a compiler with the command line tools from Apple; clang or gcc. It comes down to a matter of preference, really. They both do the same thing.
So, to compile your cpp file, you will first need to have the terminal in the same working directory as the file. Then enter the following command:
g++ -o ProgramName resistance.cpp
Some additional flags for g++ or clang++ are:
-L<library search path> - adds an additional search path for libraries
-I<header search path> - adds an additional header search path
-l<library name> - links a library to your project
-D<preprocessor definition> - (such as _DEBUG)
-framework <framework name> - Links a framework in OS x.
-Wall - outputs all compiler warnings
in g++ if you plan on using C++11 features, you must use the following flag:
in clang++ you must use:
Also, the version of gcc that apple provides is gcc 4.2, which is outdated and doesn't have C++11 support (afaik). Apple has only 'approved' this version for use, because they tailor the release to their products. However, you can install the most up to date version of gcc or clang (that supports C++11) with some software called macports, which is akin to linux's apt-get.
This link details that process. http://www.ficksworkshop.com/blog/14-coding/65-installing-gcc-on-mac