New To Mac-Forums?

Welcome to our community! Join the discussion today by registering your FREE account. If you have any problems with the registration process, please contact us!

Get your questions answered by community gurus Advice and insight from world-class Apple enthusiasts Exclusive access to members-only contests, giveaways and deals

Join today!

 
Start a Discussion
 

Mac-Forums Brief

Subscribe to Mac-Forums Brief to receive special offers from Mac-Forums partners and sponsors

Join the conversation RSS
OS X - Development and Darwin Discussion and questions about development for Mac OS X.

Beginner C++ question


Post Reply New Thread Subscribe

 
Thread Tools
O'Brien

 
Member Since: Oct 16, 2009
Posts: 18
O'Brien is on a distinguished road

O'Brien is offline
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?
QUOTE Thanks
cuhnool

 
cuhnool's Avatar
 
Member Since: Jun 02, 2008
Location: Louisville
Posts: 1,502
cuhnool is a jewel in the roughcuhnool is a jewel in the rough
Mac 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

cuhnool is offline
Can you provide links to the programs?

QUOTE Thanks
O'Brien

 
Member Since: Oct 16, 2009
Posts: 18
O'Brien is on a distinguished road

O'Brien is offline
here is one of the codes I could not get to compile.
QUOTE Thanks
cuhnool

 
cuhnool's Avatar
 
Member Since: Jun 02, 2008
Location: Louisville
Posts: 1,502
cuhnool is a jewel in the roughcuhnool is a jewel in the rough
Mac 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

cuhnool is offline
Quote:
Originally Posted by O'Brien View Post
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.

QUOTE Thanks
O'Brien

 
Member Since: Oct 16, 2009
Posts: 18
O'Brien is on a distinguished road

O'Brien is offline
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.
QUOTE Thanks
cuhnool

 
cuhnool's Avatar
 
Member Since: Jun 02, 2008
Location: Louisville
Posts: 1,502
cuhnool is a jewel in the roughcuhnool is a jewel in the rough
Mac 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

cuhnool is offline
Quote:
Originally Posted by O'Brien View Post
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

QUOTE Thanks
O'Brien

 
Member Since: Oct 16, 2009
Posts: 18
O'Brien is on a distinguished road

O'Brien is offline
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 ?
QUOTE Thanks
cuhnool

 
cuhnool's Avatar
 
Member Since: Jun 02, 2008
Location: Louisville
Posts: 1,502
cuhnool is a jewel in the roughcuhnool is a jewel in the rough
Mac 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

cuhnool is offline
Quote:
Originally Posted by O'Brien View Post
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.

QUOTE Thanks
O'Brien

 
Member Since: Oct 16, 2009
Posts: 18
O'Brien is on a distinguished road

O'Brien is offline
Alright I'll give it a try. Thanks!
QUOTE Thanks
cuhnool

 
cuhnool's Avatar
 
Member Since: Jun 02, 2008
Location: Louisville
Posts: 1,502
cuhnool is a jewel in the roughcuhnool is a jewel in the rough
Mac 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

cuhnool is offline
Quote:
Originally Posted by O'Brien View Post

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.

QUOTE Thanks
cuhnool

 
cuhnool's Avatar
 
Member Since: Jun 02, 2008
Location: Louisville
Posts: 1,502
cuhnool is a jewel in the roughcuhnool is a jewel in the rough
Mac 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

cuhnool is offline
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

QUOTE Thanks
O'Brien

 
Member Since: Oct 16, 2009
Posts: 18
O'Brien is on a distinguished road

O'Brien is offline
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!
QUOTE Thanks
cuhnool

 
cuhnool's Avatar
 
Member Since: Jun 02, 2008
Location: Louisville
Posts: 1,502
cuhnool is a jewel in the roughcuhnool is a jewel in the rough
Mac 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

cuhnool is offline
Quote:
Originally Posted by O'Brien View Post
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++ !

QUOTE Thanks

Post Reply New Thread Subscribe


« dynamic mwmory allocation in objective c | compiler question »
Thread Tools

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Posting 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 Off
Forum Jump

Similar Threads
Thread
Thread Starter
Forum
Replies
Last Post
The QUESTION Game ToddG Schweb's Lounge 159 08-15-2007 05:25 PM
Boot-Up Question Mark Folder Impending Doom Question. bingwalker OS X - Operating System 3 07-10-2007 05:19 AM
Ask 'me' a question... eric Schweb's Lounge 22 01-12-2007 06:33 AM
Video production question macinsandiego Movies and Video 4 11-17-2004 07:39 AM
Postscript question battleangel444 OS X - Operating System 2 07-09-2004 12:45 PM

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

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

Welcome to Mac-Forums.com

Create your username to jump into the discussion!

New members like you have made this community the ultimate source for your Mac since 2003!


(4 digit year)

Already a member?