Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > C++ programming and terminal.app

C++ programming and terminal.app
Thread Tools
Fresh-Faced Recruit
Join Date: Apr 2001
Status: Offline
Reply With Quote
Apr 2, 2001, 07:10 AM
 
I am about to start a C++ course and I would really appreciate some info on how to use the terminal.app to do some programming. I have installed ProjectBuilder but it seems complicated to use - all I need is to write simple programs for now.

I know you can use Textedit to write the program. Then use "c++" in terminal to compile it. But how do you run it?

Is it similar to Java where you can use "javac" to compile and "java" to run?

If I got any of this stuff wrong please tell me!
     
Admin Emeritus
Join Date: Oct 2000
Location: Boston, MA
Status: Offline
Reply With Quote
Apr 2, 2001, 09:06 AM
 
If you're doing it solely from the terminal...

Write a text file, call it something like "main.cpp"

I've never used c++, but I assume the command line syntax is identical to cc, do a "man c++" (which will probably head you to the dev. documentation) for options.

c++ -o program main.c

The -o will make a program named "program"; without the -o it'll be a.out (I believe).

Then type ./<program name> (e.g. ./a.out) to run the thing.
"Against stupidity, the gods themselves contend in vain" (Schiller)
     
Fresh-Faced Recruit
Join Date: Apr 2001
Status: Offline
Reply With Quote
Apr 2, 2001, 10:40 AM
 
Thanks. I will try that as soon as I get home.

Incidentally, what I know comes from reading this forum. Should I be using "cc" and not "c++" to compile my code? It seems everybody is using it and nobody mentions "c++" at all.
     
Fresh-Faced Recruit
Join Date: Mar 2001
Location: Neuchâtel, Switzerland
Status: Offline
Reply With Quote
Apr 2, 2001, 11:17 AM
 
Don't forget the :

chmod u+x <program name>

to have the permission to execute it !!!

--
Francis Olof Garnier
     
Admin Emeritus
Join Date: Oct 2000
Location: Boston, MA
Status: Offline
Reply With Quote
Apr 2, 2001, 11:31 AM
 
c++ should automatically write your permissions correctly.

cc is for ObjC and C, c++ is C++ (to my knowledge).
"Against stupidity, the gods themselves contend in vain" (Schiller)
     
Addicted to MacNN
Join Date: Mar 2000
Location: London, UK
Status: Offline
Reply With Quote
Apr 2, 2001, 02:46 PM
 
cc is generally for C, I think all c++ does is invokes cc with the right commands so that it compiles C++, i'm pretty sure you can compile C++ using cc with some flags... Unsure though.
     
Fresh-Faced Recruit
Join Date: Apr 2001
Status: Offline
Reply With Quote
Apr 3, 2001, 05:20 AM
 
Yay! I tried using c++ and it seems to work. The output is the same as in the book I am using. I will try cc and see if it makes a difference but not sure about those flags though.

Thank you! You've all been a big help to a real beginner!
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 02:52 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2