+ 1

How do I write C++ code on a Mac?

I am starting a C++ class. I have a Mac and would like to use it in the class. I have read the Xcode works but I can't seem to get it to run my "hello world". Anyone coding on a Mac that could point me in the right direction? Kind of looking for a CS mentor i guess.

2nd Apr 2018, 3:18 AM
Squidy P
Squidy P - avatar
3 Respostas
+ 2
Start Xcode -> Create a new Xcode project -> select the macOS Command Line Tool template -> Next -> Fill out your project options (Don't worry about team if you don't yet have one) Organization Name can be whatever you want. Organization Identifier is usually a reverse domain (I.E. com.example). Bundle Identifier should be filled in automatically using your Organization Identifier + your Product Name. Choose C++ under Language -> Next -> Select where you wish to save the project (uncheck the Git option unless you're going to use it) -> Create -> in the left pane of your editor click on the main.cpp file that was created for you and start coding. You may need to build the project at least once prior to running it in order to get the output in the Xcode console. (Bottom of the main editor) You need to make sure that you have the Xcode tools installed as well prior to creating your first C++ project. In the terminal type: xcode-select --install
2nd Apr 2018, 4:16 AM
ChaoticDawg
ChaoticDawg - avatar
+ 2
I'm on a Mac. I ran and compiled some C++ code just now! Start the Terminal app, then go to the directory with your code (file must end in .cpp), then type: g++ fred.cpp in the Terminal. Does that work for you?
2nd Apr 2018, 3:53 AM
Emma
0
Thank you. Both methods work. I do like running it in Xcode.
2nd Apr 2018, 1:45 PM
Squidy P
Squidy P - avatar