How to read input file for C++ in Xcode

If you are currently a student from a college and taking some classes of computer science, you have to have an integrated development environment (IDE) to do your HW or to practice some coding on your computer. Many colleges might require students to use CodeBlocks, Visual Studio, or any other IDE because some college does not even provide macOS devices like an iMac. However, if you are a Mac user, using CodeBlocks or others might be uncomfortable for you. Additionally, you might have considered how to use Xcode, but there are some tricky parts on how to use Xcode. Some of my friends also gave up using Xcode because of that even they are Mac users. I have personally been using Mac for a while, so in this article, I am talking about how to input files for C++ in Xcode for people who are stuck on it.

First Step: Open your text editor on your Mac

I personally use a text editor called Atom from Github. At this time, I use these data. You can use any kind of data in the file. After you put some data in the file, press “Command + S.” Then, you can save your file anywhere you want. In this article, I saved the file on the desktop because it is easy to find it out.

Screen Shot 2016-06-27 at 19.40.56

Next Step:

Here is the trickiest part and different from any other IDE.

  1. Go to your Xcode and follow some requirements from Xcode.
  2. After you get that window you can code, there are 2 icons that look like the file on the left side. One of them is the name of the file you set up, and another one is named “product”
  3. When you click on that, a little another icon comes up and the name is exactly the same as the name of the first file you set up.
  4. Right-click on that icon, and click on “Show in Finder”

Screen Shot 2016-06-27 at 19.55.06

5. Drag the file to the place like the image.

Screen Shot 2016-06-27 at 20.06.49

If you get these steps done correctly, let’s get started with coding!

Simple Coding Time!!!

Here is what I code simply.

You do not have to code the same as mine.

Finally, let’s run it!

Screen Shot 2016-06-27 at 20.22.16

Mine is working well! How about you? If you have any questions, please comment below!

10 Replies to “How to read input file for C++ in Xcode”

  1. I struggled with this problem for weeks and all other guides were wayyy too complicated or didn’t work.. this saved me!!

  2. This literally saved my life! Suffering from this for a loooong time and finally here it goes! Thank you soooooo much!!!!!!

  3. Wow, you’re a life saver! I am in the same boat as Marc as in every other guide was way too complicated. I appreciate it!

  4. Thanks!
    This works straight away.
    And so simple….
    Now I also know where to look for files that are written by my code!!!
    So 2 problems solved….

  5. Hey, is there any way where I can read input from cin statement but the input text is present in another file ?. Basically it creates a problem when I share my code to someone because they run it with cin statement.

    Just like online gdb compiler, there I can write input only once then I can use std methods cin to read input.

  6. Thank you so much for this, I’ve been on so many forums with no solutions, finally got it to work with this!

Leave a Reply

Your email address will not be published. Required fields are marked *