Mac Forums

Mac Forums (http://www.mac-forums.com/forums/)
-   OS X - Development and Darwin (http://www.mac-forums.com/forums/os-x-development-darwin/)
-   -   Beginner C++ question (http://www.mac-forums.com/forums/os-x-development-darwin/195023-beginner-c-question.html)

O'Brien 03-17-2010 12:14 AM

Beginner C++ question
 
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?

cuhnool 03-17-2010 01:48 AM

Can you provide links to the programs?

O'Brien 03-17-2010 01:57 AM

here is one of the codes I could not get to compile.

cuhnool 03-17-2010 01:59 AM

Quote:

Originally Posted by O'Brien (Post 1019307)
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.

O'Brien 03-17-2010 02:07 AM

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.

cuhnool 03-17-2010 02:10 AM

Quote:

Originally Posted by O'Brien (Post 1019314)
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

O'Brien 03-17-2010 02:21 AM

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 ?

cuhnool 03-17-2010 02:29 AM

Quote:

Originally Posted by O'Brien (Post 1019320)
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.

O'Brien 03-17-2010 02:32 AM

Alright I'll give it a try. Thanks!

cuhnool 03-17-2010 02:39 AM

Quote:

Originally Posted by O'Brien (Post 1019320)

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.

cuhnool 03-17-2010 03:13 AM

Go to Project >> Add to Project...


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


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


Click Add again


Replace the highlighted line with curses.h


Delete the highlighted line


Delete the highlighted line


Click Build and Go

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


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.


--

Hope this helps you out! Should work for you now :D

O'Brien 03-17-2010 04:23 PM

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!

cuhnool 03-17-2010 05:44 PM

Quote:

Originally Posted by O'Brien (Post 1019648)
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++ !


All times are GMT -4. The time now is 09:52 PM.

Powered by vBulletin
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.