Want to highlight a helpful answer? Upvote!

Did someone help you, or did an answer or User Tip resolve your issue? Upvote by selecting the upvote arrow. Your feedback helps others! Learn more about when to upvote >

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

How do I save (& run) a file as a .cpp?

My son is taking a C++ class and is trying to figure out how to save (& run) a file as a .cpp in a Mac? (Terminal does not understand g++ command.)

He'll ask his professor on Monday but I thought I'd try to help him out now. I didn't find anything through the 'search forum' option.

He has a MacBook w/Snow Leopard. Thanks!

lablady

eMac, iMac, MacBook, Mac OS X (10.6.6)

Posted on Jan 15, 2011 11:32 AM

Reply
Question marked as Best reply

Posted on Jan 15, 2011 11:41 AM

The first step is to install Xcode. That will give you all of the g++ commands in the Terminal. You already have vim, etc. so once Xcode is installed the Mac's Terminal will operate the same as any Linux machine. If he is just now learning C++, I would advise sticking with the Terminal for now. As some point he may want to build true MacOS X applications with Xcode, but that wouldn't help with a class.
8 replies
Question marked as Best reply

Jan 15, 2011 11:41 AM in response to lablady

The first step is to install Xcode. That will give you all of the g++ commands in the Terminal. You already have vim, etc. so once Xcode is installed the Mac's Terminal will operate the same as any Linux machine. If he is just now learning C++, I would advise sticking with the Terminal for now. As some point he may want to build true MacOS X applications with Xcode, but that wouldn't help with a class.

Jan 15, 2011 11:42 AM in response to lablady

He will need the gcc compiler that is part of the Mac OS X Developer Tools. You can download it here:

http://developer.apple.com/technologies/xcode.html

Note that you will need to join the Apple Developer program, which you can do for free here:

http://developer.apple.com/programs/register/

Note that, to get the best answers, further questions along these lines should be directed to one of the developer forums here:

http://discussions.apple.com/category.jspa?categoryID=162

Jan 15, 2011 11:44 AM in response to thomas_r.

Thomas A Reed wrote:
He will need the gcc compiler that is part of the Mac OS X Developer Tools. You can download it here:

http://developer.apple.com/technologies/xcode.html

Note that you will need to join the Apple Developer program, which you can do for free here:

http://developer.apple.com/programs/register/


You only need to join the Apple Developer program if you want to download Xcode. It would be better to use the Xcode installer that is in the "Optional Install" folder on your MacOS X installer DVD. Otherwise, it is something like a 1.6 GB download that will take a while.

Jan 15, 2011 1:03 PM in response to etresoft

Ahh, is it still on the install disks? I remember when it came on a separate disk, but I haven't paid attention to that lately, and with all the changes Apple has made to the developer program lately, I thought it might be download-only now. Thanks for the clarification!

See, excellent example of why the developer forums are the best places to ask these sorts of things! 😉

Jan 15, 2011 1:54 PM in response to thomas_r.

Thomas A Reed wrote:
Ahh, is it still on the install disks? I remember when it came on a separate disk,


Yes. That was back when the OS came on CD-ROM. The version on the DVD doesn't have tools for iOS development, but it is fine for MacOS X development and especially a C++ class. People complain, and rightly so, that each incremental update of Xcode is another multi-gigabyte download.

Jan 15, 2011 6:58 PM in response to lablady

lablady wrote:
Thank you all. Unfortunately, he left the installation DVD's home. Guess I'll have to mail them to him.


If he is at a university he should be able to sign up for a free developer account and download Xcode fairly quickly.

Can any of you tell him how he can save a file as a .cpp, though? Thanks!!


That depends on what he is using. To write source code, one must use a plain text editor. Xcode includes such an editor. There are a number of editors built in to the Terminal, such as vi and nano. Basic understanding of how to use vi would be very, very useful. If he wants something fancier, there is always TextWrangler and at least two dozen like it.

How do I save (& run) a file as a .cpp?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.