Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

musique

macrumors regular
Original poster
Apr 10, 2009
222
5
OK. I'm taking a C++ course and everyone is on Windows. I have been successful in learning how to use Terminal to compile (g++) and run my very basic programs.

I have Xcode on my Mac and I've been told that it's a complete IDE. But if I copy the source code into an Xcode window I just have the window. There doesn't appear to be any way to compile and run the program.

Obviously I'm missing something. Could someone help point me in the right direction?

Thanks in advance.

C++Xcode.png
 

Senor Cuete

macrumors 6502
Nov 9, 2011
430
31
Create an XCode project. You probably want a command line project or maybe a single window project. Put this code in the main file and run it.
 

mfram

Contributor
Jan 23, 2010
1,354
401
San Diego, CA USA
For simple console programs like you have shown, the Xcode IDE is probably overkill. You would have to make a separate project for each program. It's possible, but more work than it's worth.

The IDE is much more useful at making full-fledged Mac, iPad, or iPhone programs because there are lots of details that need to be filed in when they are built.

At this early stage in your programming career my recommendation is to continue with the simple command-line approach you have been using.
 

musique

macrumors regular
Original poster
Apr 10, 2009
222
5
For simple console programs like you have shown, the Xcode IDE is probably overkill. You would have to make a separate project for each program. It's possible, but more work than it's worth.

The IDE is much more useful at making full-fledged Mac, iPad, or iPhone programs because there are lots of details that need to be filed in when they are built.

At this early stage in your programming career my recommendation is to continue with the simple command-line approach you have been using.

Thank you for your responses.

mfram, you stated what I had been thinking. For now, I'm content just writing my programs in my editor (BBEdit) and using the command line for compiling and running them.

I had spoken to a few people who'd recommended Xcode and thought I'd give it a shot. But it wanted to know if I was designing the program for MacOS or iOS et al. So for the time being I'll stick with my current workflow.

Again, thank you.
 

chown33

Moderator
Staff member
Aug 9, 2009
10,996
8,880
A sea of green
The best way to get started with Xcode is a tutorial.

Tutorials for GUI apps are far more common than for command line tools. However, see here:
https://www.raywenderlich.com/128039/command-line-programs-macos-tutorial

I found that by googling xcode beginner tutorial command line .

The language in that tutorial is Swift, not C++, but the procedures for using Xcode are otherwise the same. That is, you should be able to substitute a C++ file for the Swift file, and it should still work. However, I recommend doing that tutorial exactly as given first, and only modifying the process after success has been achieved with Swift.
 

Toutou

macrumors 65816
Jan 6, 2015
1,082
1,575
Prague, Czech Republic
For simple console programs like you have shown, the Xcode IDE is probably overkill. You would have to make a separate project for each program. It's possible, but more work than it's worth.

Pressing four buttons isn't that much work. I agree that Xcode is capable of much more, but it's totally okay even for a simple terminal app. The debugging options and real time corrections are pretty useful.

@musique: In Xcode, choose File -> New -> Project –> OS X Application (Command Line Tool), enter the project name and choose C++ as the language, then choose a directory and press Create. Bam, done, you're ready to code and compile.
 

hiddenmarkov

macrumors 6502a
Mar 12, 2014
685
492
Japan
OP based on our picture it looks like you may have have double clicked on the .cpp file.

When you do this, for any file (I do this sometimes taking a few classes in swift and iOS classes work has me in right now), it will open up a text edit window that will lose the functionality you may be seeking. It will be just the text editor window.

If you single click and assuming you haven't got crazy with the window arrangements, your file will show in the center panel and up in the upper right hand corner right next to the close/minimize/maximize buttons with will be the "play" looking arrow to compile and run your code.

"fun" feature of Xcode. has many you will come the more you use it. Its an iDE that needs some getting used to, has for me. 2nd time around, tried using in the past, this class has me going back to it.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.