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

kantha

macrumors newbie
Original poster
Jun 1, 2006
3
0
Hi everybody,

Since I have time this summer, I decided to teach myself C++. So far, I've installed Xcode, and I'm making my way into Prata's book "C++ Primer Plus."

Now, I'm not understanding the difference between a "BSD" C++ file and a "Carbon" C++ file; nor the difference between the many project types. Which am I supposed to use? Next, why are two files created, one with a .h extention and the other with a .cpp? What's the difference?

Also, I'm having trouble getting my first program to run. There's an error, but I'm not understanding what the hell it means. I'm not sure how the debugger works. When I try to use it, a blank screen appears.

I'm sure these must sound like silly questions, but you have to excuse me.
 

savar

macrumors 68000
Jun 6, 2003
1,950
0
District of Columbia
kantha said:
Hi everybody,

Since I have time this summer, I decided to teach myself C++. So far, I've installed Xcode, and I'm making my way into Prata's book "C++ Primer Plus."

Now, I'm not understanding the difference between a "BSD" C++ file and a "Carbon" C++ file; nor the difference between the many project types. Which am I supposed to use? Next, why are two files created, one with a .h extention and the other with a .cpp? What's the difference?

Also, I'm having trouble getting my first program to run. There's an error, but I'm not understanding what the hell it means. I'm not sure how the debugger works. When I try to use it, a blank screen appears.

I'm sure these must sound like silly questions, but you have to excuse me.

First rule of learning to program: when you ask for questions online, be as specific as possible. Submit a short but complete piece of code which illustrates your problem and the exact error message you receive.

Don't mess around with XCode just yet. Write your programs in a text editor (vi if you're super cool) and then compile them at the command line with g++.

But to answer your question, those different projects are templates designed for developing different types of apps. BSD project means an app that you'd run from the command line...probably most appropriate for a C++ beginner, but like I said above just use the Terminal. Carbon means a C++ program which uses the Carbon API...which is an API based on the OS9 API used for writing GUI applications.

The .h file is a header file. They should cover that in your book. A header file is where you declare the "interface" to your code...i.e. what public methods it defines, classes, static variables, constants, etc. The actual implementation goes in the C++ file, which has the .cpp extension.

The best way to use the debugger is, once again, from the command line. The learning curve is a little steep but its far more beneficial once you learn it. A debugger is invoked from the command line by typing "gdb <executable>", where <executable> is the actual binary file -- not the same thing as an application package which you'll learn about further down the road.
 

kantha

macrumors newbie
Original poster
Jun 1, 2006
3
0
All right, I'm having some troubles. I've now downloaded both Vim and G++, but don't know how to use them.

I write the source code on Vim and then compile it, through G++, on Terminal, right? How do I do the last part? Also, I downloaded GCC directly through this site here: http://aixpdslib.seas.ucla.edu/new.html. Is that okay?

Is there anything else I need to know?

Thanks.
 

theorem7

macrumors member
Feb 7, 2006
52
0
I don't think it was necesary to download GCC or G++, I believe these are already built into the OS. To compile it, just go into terminal and type g++ filename and hit return, it should compile it and put the executable right next to the .cpp file. Then just open up the executable in terminal, and it should display the results!

(I'm new to this too, so forgive me if I'm wrong about anything, but this worked for me!)

edit: I just realized that Vim is built into the OS already too, try typing man vim in Terminal to learn about it.
 

Catfish_Man

macrumors 68030
Sep 13, 2001
2,579
2
Portland, OR
theorem7 said:
I don't think it was necesary to download GCC or G++, I believe these are already built into the OS. To compile it, just go into terminal and type g++ filename and hit return, it should compile it and put the executable right next to the .cpp file. Then just open up the executable in terminal, and it should display the results!

(I'm new to this too, so forgive me if I'm wrong about anything, but this worked for me!)

edit: I just realized that Vim is built into the OS already too, try typing man vim in Terminal to learn about it.

GCC is installed when you install Xcode.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.