Mac Xcode and C++ — Beginning

Mac Xcode and C++ — Beginning

Image for post

Yes you read the title right! We all know Mac and Xcode are made for each other, They are just like Romeo and Juliet ? and Xcode works magically for iOS/MacOS development with Objective C or Swift(??) but what we dont know is Xcode works great for c,c++ as well.

Usually first hand advice we get is to use some other IDE and there are tons of them and they all work great. If you are using them and happy then this post wont make sense for you but if you want to do everything using a single IDE like me than you should give Xcode a chance.

I always loved c++ but never used it a lot other than for writing short small programs, since I am in my final year and we have companies coming in for placements, I have to practice c++. I started with command line but as you get into more complicated code which require you to debug it again and again it gets a bit rigrous.

For someone who loves Command line you can directly use this to compile and run a c++ program where helloWorld.cpp is the file name and helloWorld is the output file.

gcc -o helloWorld.cpp helloWorld./helloWorld

Here how you can start with Xcode for C++ :

Xcode > File > New > Project > macOS > Command Line Tool > Next > Language -> C++ > Next

Image for postImage for post

just like that you have the project up and running which will run your C++ program. You can also choose C,Swift or Objective C.

Image for post

As you can see, the above image shows that you can simply run the program : main.cpp is the file which will run the main function first. The bottom right panel works as a terminal which will show you the output and you can take input from the same too.

This is just the Beginning of how to run a simple program. As I am also learning more and more of Xcode and C++, In the next few medium posts I will be talking about how you can add Multiple files, Multiple targets in a single project to keep all your code in a single place. Renaming the main.cpp file to something else. File handling and breakpoints(Basics). Command line arguments(I am working on this and will figure this out).

I wrote about adding Multiple files/Multiple Targets here :

Mac Xcode and C++ ? Project/Programs Management

This post talks more about how one can manage multiple c++ files in a single target or how one can add multiple targets?

medium.com

I wrote about File Handling here :

Mac Xcode and C++ ? File Handling

I am glad to keep up and be able to write the third post. If you are coming here for the first time and confused how to?

medium.com

Note : I am also learning, there can be chances where there will be a better way to do things. If you know about it please let me know so we can all learn 🙂

Also I am falling more in more love with C and C++, if you know something or can direct me to how one can use C++ to write something more than a program that would be awesome.

20