Beginner C++ question

Joined
Oct 16, 2009
Messages
18
Reaction score
0
Points
1
Hello, I am learning C++ and am using Xcode as my IDE. This may sound like a dumb question but are there different types of C++? I have been trying to compile some basic source code from planet-source-code.com (calculators and things like that). Some of them work without a problem but the majority have several errors and will not build. I'm not sure if this makes a difference but under compatibility they all say general C++ (which I assumed is what I would want). Could someone please explain to me why this is happening?
 
Joined
Jun 2, 2008
Messages
1,502
Reaction score
35
Points
48
Location
Louisville
Your Mac's Specs
MacBook 2.1GHz Core 2 Duo | 1GB RAM | OS X 10.6.3 | 250GB External HD | 8GB iPod Touch 1st Gen 3.1.3
Can you provide links to the programs?
 
Joined
Jun 2, 2008
Messages
1,502
Reaction score
35
Points
48
Location
Louisville
Your Mac's Specs
MacBook 2.1GHz Core 2 Duo | 1GB RAM | OS X 10.6.3 | 250GB External HD | 8GB iPod Touch 1st Gen 3.1.3
here is one of the codes I could not get to compile.

Also, have you learned the "Hello, World!" program? You should start from the very beginning, such as learning what libraries are, syntax, header files, variables, stuff like that. Learning the absolute basics will help give you a grasp of what to look for in a program when it relates to finding errors.

I would suggest picking up a book for learning C++, or going here. I myself will occasionally glance through Sams Teach Yourself C++ book. Aside from that, the main book I use to learn C++ is from Lawrenceville Press, and it's called "A Guide to Programming in C++". It's ISBN is 1-879233-90-8 if you want to pick it up.
 
OP
O
Joined
Oct 16, 2009
Messages
18
Reaction score
0
Points
1
Yes I have learned the "Hello World!" as well as variables, functions, arrays etc. (I am currently working my way through a tutorial) I've just been trying to teach myself some practical programming by analyzing other peoples programs. Thanks for the suggestions. I'll definitely look into those books.
 
Joined
Jun 2, 2008
Messages
1,502
Reaction score
35
Points
48
Location
Louisville
Your Mac's Specs
MacBook 2.1GHz Core 2 Duo | 1GB RAM | OS X 10.6.3 | 250GB External HD | 8GB iPod Touch 1st Gen 3.1.3
Yes I have learned the "Hello World!" as well as variables, functions, arrays etc. (I am currently working my way through a tutorial) I've just been trying to teach myself some practical programming by analyzing other peoples programs. Thanks for the suggestions. I'll definitely look into those books.

Alright, just checking if you did, lol. It would be quite the challenge jumping right in without necessary knowledge. But you got that covered so we're good there ;)

I am looking at the source code now.

**EDIT**

Looked at the errors. You do not have the conio.h directory. conio.h is a MS-DOS header file, so it's not included with OS X.

more information
 
OP
O
Joined
Oct 16, 2009
Messages
18
Reaction score
0
Points
1
Ah thank you that makes sense. So I'm assuming I was wrong in thinking that (general) C++ means that it would be universal. Or did that person just put the wrong category?

Oh I see your link now about making conio.h readable in osx. I'm still a bit confused about what the syntax would be though. Would it be #include <conio.h> /usr/lib/libncurses.dylib ?
 
Joined
Jun 2, 2008
Messages
1,502
Reaction score
35
Points
48
Location
Louisville
Your Mac's Specs
MacBook 2.1GHz Core 2 Duo | 1GB RAM | OS X 10.6.3 | 250GB External HD | 8GB iPod Touch 1st Gen 3.1.3
Ah thank you that makes sense. So I'm assuming I was wrong in thinking that (general) C++ means that it would be universal. Or did that person just put the wrong category?

The only header file I know of that doesn't work with Unix-based systems is conio.h

If there are others, I'm sure there are workarounds or other header files that have identical functions. There shouldn't be too much of a difference.
 
Joined
Jun 2, 2008
Messages
1,502
Reaction score
35
Points
48
Location
Louisville
Your Mac's Specs
MacBook 2.1GHz Core 2 Duo | 1GB RAM | OS X 10.6.3 | 250GB External HD | 8GB iPod Touch 1st Gen 3.1.3
Oh I see your link now about making conio.h readable in osx. I'm still a bit confused about what the syntax would be though. Would it be #include <conio.h> /usr/lib/libncurses.dylib ?

I just saw this, lol

Nope. I corrected the program, and I have it working. I'll show you in a bit, let me grab some snapshots.
 
Joined
Jun 2, 2008
Messages
1,502
Reaction score
35
Points
48
Location
Louisville
Your Mac's Specs
MacBook 2.1GHz Core 2 Duo | 1GB RAM | OS X 10.6.3 | 250GB External HD | 8GB iPod Touch 1st Gen 3.1.3
Go to Project >> Add to Project...

Screenshot2010-03-17at14304AM.png

Press Command+Shift+G to bring up the "Go to the folder..." pane. Type in /usr/lib. Click Go

Screenshot2010-03-17at14343AM.png

Scroll down until you find the libcurses.dylib file. Click Add

Screenshot2010-03-17at14403AM.png

Click Add again

Screenshot2010-03-17at14415AM.png

Replace the highlighted line with curses.h

Screenshot2010-03-17at14430AM.png

Delete the highlighted line

Screenshot2010-03-17at14454AM.png

Delete the highlighted line

Screenshot2010-03-17at14504AM.png

Click Build and Go

Click the Console button (the arrow is pointing to it)

Screenshot2010-03-17at14518AM.jpg

Go to the Console, and type in an equation using the five operators. The equation I used was 5 ^ 5 which came out to 3,125. I then typed in n to end the program.

Screenshot2010-03-17at14608AM.png

--

Hope this helps you out! Should work for you now :D
 
OP
O
Joined
Oct 16, 2009
Messages
18
Reaction score
0
Points
1
borden of

Ah thank you so much. I was still getting the error: 'clrscr' was not declared in this scope. I tried removing this function (?) from the code as it did not seem to have a purpose. When I did that it ran fine but when prompted if I wanted to solve another problem I typed "y" and the program exited as if I had typed "n".

edit* Oh now I see the part of your post about deleting the textgreen and clrscr.

edit** Never mind I fixed it. Thanks again for all your help!
 
Joined
Jun 2, 2008
Messages
1,502
Reaction score
35
Points
48
Location
Louisville
Your Mac's Specs
MacBook 2.1GHz Core 2 Duo | 1GB RAM | OS X 10.6.3 | 250GB External HD | 8GB iPod Touch 1st Gen 3.1.3
Ah thank you so much. I was still getting the error: 'clrscr' was not declared in this scope. I tried removing this function (?) from the code as it did not seem to have a purpose. When I did that it ran fine but when prompted if I wanted to solve another problem I typed "y" and the program exited as if I had typed "n".

edit* Oh now I see the part of your post about deleting the textgreen and clrscr.

edit** Never mind I fixed it. Thanks again for all your help!

You're welcome! Glad to help out. Good luck with your further studies in C++ !
 

Shop Amazon


Shop for your Apple, Mac, iPhone and other computer products on Amazon.
We are a participant in the Amazon Services LLC Associates Program, an affiliate program designed to provide a means for us to earn fees by linking to Amazon and affiliated sites.
Top