Society of Robots - Robot Forum

Software => Software => Topic started by: BANE on June 09, 2008, 06:18:02 PM

Title: best program to learn C++?
Post by: BANE on June 09, 2008, 06:18:02 PM
Hello, I've got alot of experience programming robots using BASIC but I want to learn C++.  Not just for robots, but to make a simple program.  Does anyone have any suggestions what compiling program to get for noobs? :P

Bane
Title: Re: best program to learn C++?
Post by: Yakri on June 09, 2008, 09:50:31 PM
I use Bloodshed Dev-C++ and it works great for me, although I am still a total noobie at it. That should work fine for windows, but if your running a *nix operating system or a mac OS then i think you will need a different one.
Title: Re: best program to learn C++?
Post by: Webbot on June 10, 2008, 01:07:51 PM
The standard AVR tools contain a C++ compiler as well as the C compiler. See my posting in the member forums for a C++ library to help you out. But if you need to learn C++ from scratch then consult Google, books etc etc.
Title: Re: best program to learn C++?
Post by: krich on June 11, 2008, 10:51:22 AM
Probably one of the best ways to learn C++ is on a Linux/Unix system at the command prompt.  If you have a Linux/Unix system handy, you can get quite far with very little effort.  Unless you're familiar with Linux/Unix, building a system just to learn C++ is probably not the best use of your time.

For the Windows oriented person, Microsoft has free versions of their Visual Studio languages, C++ is here (http://www.microsoft.com/express/vc/).  Its adherence to the C++ standards and standard libraries is at times questionable, but for your purposes it'll do just fine.  Just realize when you move from a PC to an MCU like the AVR series, that Microsoft uses a superset of the standard C++ libraries, and WinAVR, because of memory and processor constraints, uses a subset of the standard C++ libraries.  Not everything you can do on a PC is going to work on an AVR.

I find programming MCUs much more difficult because you constantly have to be aware of the data space usage, program size, and algorithm optimization.  All of those concerns/pitfalls make it huge effort to spit out your first "blink" program if you're still struggling with the language.  For that reason, it might be better to learn C++ on a PC first, then jump into MCU programming.  Hopefully by then WinAVR will properly support C++.

Also, as Webbot suggested, get a book.  A good one.  Something you can use as a reference.  It's been years since I bought a book on C++, but the one I bought and learned from is "The C++ Programming Language" by Bjarne Stroustrup.  Not sure its even still in print, or if the C++ standards have deprecated its contents.

(haha...cool...I just pulled the book off my shelf and I must have been using the original receipt as a bookmark.  It was purchased on 6/26/1989 at 4:53pm for $33.75.  How it stayed in the book for that long with that much use, I have no idea.)
Title: Re: best program to learn C++?
Post by: BANE on June 11, 2008, 02:51:36 PM
Quote
For the Windows oriented person, Microsoft has free versions of their Visual Studio languages, C++ is here.  Its adherence to the C++ standards and standard libraries is at times questionable, but for your purposes it'll do just fine.
  Thanks, thats more of what i'm looking for.  (2 hr and 36min to download though :P :P :P, time to take a nap :D)

Quote
haha...cool...I just pulled the book off my shelf and I must have been using the original receipt as a bookmark.  It was purchased on 6/26/1989 at 4:53pm for $33.75.  How it stayed in the book for that long with that much use, I have no idea.)
  lol

I first want to make simple logic programs on my PC for starters, because i might have to program a PLC for a machine at work.  However, I'd like to also program robots later in C++ rather than BASIC

Bane
Title: Re: best program to learn C++?
Post by: BANE on June 11, 2008, 03:10:37 PM
what about this one http://www.creationengine.com/html/p.lasso?p=14332 (http://www.creationengine.com/html/p.lasso?p=14332)   Pretty cheap to me and I qualify as a student.
Bane
Title: Re: best program to learn C++?
Post by: dolinay on June 12, 2008, 08:30:39 AM
Hi,
I don't think you need to buy VS Studio Pro just to learn C++. You will not be able to write programs for robots in VS - at least not for the cheap ones which use microcontrollers, such as Atmel or PIC.  To learn C++ the free (Express) edition of Visual C++ will do fine. Even better, I'd first buy a book or find a good tutorial on the internet and then use the program which my learning text uses. The book may even include CD with Visual C++ or other development environment, so no need to download for 3 hours ;) 
Title: Re: best program to learn C++?
Post by: pomprocker on June 12, 2008, 10:48:26 AM
from the few C++ courses i've taken in college...the textbooks always come with the same free IDE called MetroWorks CodeWarrior.
Title: Re: best program to learn C++?
Post by: dolinay on June 12, 2008, 12:17:06 PM
I know Code Warrior from programing Freescale microcontrollers HC08. There are versions of this IDE which can compile code for many microcontrollers, DSPs and I guess also for Windows which you used in your courses. For a start you should probably write simple Win32 "Console applications" - that's exe file which displays black command prompt window when you start it- In this type of program you can easily output results from your programu using "printf" or "cout". Don't get into any GUI stuff if you intend to use C++ for programming microcontrollers, you will not need it and it's too complex.
The advantage of Code Warrior is that you could stick with the same environment when moving from Windows programs to microcontroller, but MS Visual Studio is much nicer to work with - I'd say it's the standard of development IDE, the other IDEs are something like a year or 2 behing it... I know some people will disagree  :)
Title: Re: best program to learn C++?
Post by: BANE on June 12, 2008, 07:19:50 PM
Thanks for the posts guys :).  I think buying a book for starters with a CD is probably my best bet.  Any idea what type and where to buy a good one (preferabley at a well-known books store or something ;))  I've googled it and i get a lot, theres got to be one thats the best ;D)

Bane
Title: Re: best program to learn C++?
Post by: krich on June 12, 2008, 10:42:20 PM
For a start you should probably write simple Win32 "Console applications" - that's exe file which displays black command prompt window when you start it- In this type of program you can easily output results from your programu using "printf" or "cout". Don't get into any GUI stuff if you intend to use C++ for programming microcontrollers, you will not need it and it's too complex.

Good point dolinay.  I was heading back to this thread to say this exact thing.  Stay with Win32 console apps because that's more like what the MCU programming environment is like.

Later.
Title: Re: best program to learn C++?
Post by: pomprocker on June 13, 2008, 09:51:03 AM
I was using a book called "Big C++"
Title: Re: best program to learn C++?
Post by: BANE on June 13, 2008, 05:00:19 PM
Ok Ive just download Dev-C++ and I'm trying out a program that can take the average of three numbers.  However, I just noticed something when i had compiling errors on a code thats i saw work on You-tube.  And then i happened, i have Vista on my laptop and the requirments didn't say if they support it.   :-[
Any body have any trouble with vista or even try it?

Bane
Title: Re: best program to learn C++?
Post by: emmannuel on June 13, 2008, 05:16:20 PM
Ok Ive just download Dev-C++ and I'm trying out a program that can take the average of three numbers.  However, I just noticed something when i had compiling errors on a code thats i saw work on You-tube.  And then i happened, i have Vista on my laptop and the requirments didn't say if they support it.   :-[
Any body have any trouble with vista or even try it?

Bane

I don't know anything to help you there but all I can say is C/C++ can be tough to learn.  Seriously start out with a simple "hello world" C program see if you still get your errors.  It might be just things in the compiler that needs to be configured properly.

I would recommend starting off slow learn C basics.  Loops will be similar to stuff you've done in Basic.  Learn how C works, syntax, logic, functions.  That alone will help you quite a bit.  There are more things like structs and pointers that you want to learn but aren't 100% necessary from what I've played around with in microcontrollers.  C++ just builds on C and takes things to a whole new level and a slightly different way of thinking.
Title: Re: best program to learn C++?
Post by: BANE on June 13, 2008, 06:32:04 PM
Quote
just things in the compiler that needs to be configured properly.
Do you mean that you have to tell the compiler what to recognize???

Bane
Title: Re: best program to learn C++?
Post by: emmannuel on June 13, 2008, 06:41:13 PM
Quote
just things in the compiler that needs to be configured properly.
Do you mean that you have to tell the compiler what to recognize???

Bane

Sorta, there are ton of settings and I've never used that compiler.  Some of the settings involve telling to tell the compiler where to set the displaying of warnings/levels at.  It might be compiling just fine and its just shooting a ton of warnings flags.
Title: Re: best program to learn C++?
Post by: BANE on June 13, 2008, 06:48:28 PM
Oh, figure out whats wrong with my code.  Had ( ) around the main program instead of { }, big difference :P

Bane
Title: Re: best program to learn C++?
Post by: emmannuel on June 13, 2008, 07:10:28 PM
Oh, figure out whats wrong with my code.  Had ( ) around the main program instead of { }, big difference :P

Bane

Welcome to C programming :D

I hope you always kept the same case for your variable names.  Thats and many other things you'll realize Basic let you get away with, that other languages won't.
Title: Re: best program to learn C++?
Post by: Rand alThor on June 15, 2008, 03:53:50 PM
I don't know about the rest of you guys, but I'm a veteran programmer, especially in C++, and I think the best way to learn C++ is to pick up a copy of Beginning Programming for Dummies. It's how I learned (programming in general and C++). I don't recommend getting C++ for dummies because the book is harder to understand and most of it is covered in Beginning Programming for dummies.
Title: Re: best program to learn C++?
Post by: izua on June 16, 2008, 07:56:24 AM
devC++ sucks, IMO. no code folding, poor unicode support, ugly IDE, little flexibility with project files.
a bit better is wxdevC++, which has the unicode and project files issues addressed (plus a RAD tool for wxWidgets).

I use code::blocks, which is all i want. it has mingw with it, and i found a distro that included avrgcc.
it has an avr project template if you really want it, so you can compile and manage both your pc software and your avr software from the same IDE.
Title: Re: best program to learn C++?
Post by: benji on June 16, 2008, 03:02:26 PM
i did buy (C++ a beginners guide by Mcraw hill)
its a good start
Title: Re: best program to learn C++?
Post by: izua on June 16, 2008, 07:43:00 PM
the best way to learn C++ is to look over other people's code (after you learn the basics like structures, keywords, etc). Really. try www.pscode.com for tons of C/C++ code.
Title: Re: best program to learn C++?
Post by: Webbot on June 17, 2008, 12:31:38 PM
Or download my C++ libraries from the Members Tutorials....... plug.
Title: Re: best program to learn C++?
Post by: BANE on June 18, 2008, 04:07:45 PM
I was just thinking about making a C++ program that can factor a polynomial.  I was thinking i might actually pretty easy.......maybe :o.  I  could use the quadratic formula and hopefully be able to even get imaginary answers out of it.  Sound pretty cool?

Any idea how to enter the ax^2+bx+c without entering it in a different line every time?

Bane
Title: Re: best program to learn C++?
Post by: emmannuel on June 18, 2008, 07:43:46 PM
I was just thinking about making a C++ program that can factor a polynomial.  I was thinking i might actually pretty easy.......maybe :o.  I  could use the quadratic formula and hopefully be able to even get imaginary answers out of it.  Sound pretty cool?

Any idea how to enter the ax^2+bx+c without entering it in a different line every time?

Bane

Use the plus sign as the delimiter, and parse out the tokens.
Title: Re: best program to learn C++?
Post by: emmannuel on June 18, 2008, 07:54:44 PM
Use the plus sign as the delimiter, and parse out the tokens.

Sorry if I wasn't very clear.

You can do a for loop into the char array to find out if you have a plus sign. Note that location.
So from the beginning of the array (0) to that delimiter location (4) minus one you have one token. (ax^2)

Using that found plus sign location you loop through the array again looking for the next plus sign.
From the first plus sign (4) plus one, to the last plus sign (7) minus one you have the next token.  (bx)

From the last plus sign loop to find NULL.
From the second plus sign (7) plus one, to the NULL (9) minus one you have the last token. (c)
Title: Re: best program to learn C++?
Post by: Admin on June 22, 2008, 05:38:07 PM
I learned C++ using CodeWarrior . . . it was the default IDE that CMU used to teach programming before they converted to Java . . .

I learned by taking classes and reading the textbook . . .
Title: Re: best program to learn C++?
Post by: mangoraisin on June 29, 2008, 02:24:51 AM
I use Bloodhsed -dev c++, and the gcc compiler,

BUT, use 'C',   'C' is a great language, a powergul language, a popular language.

C++, is a whole bunch of messy object oriented stuff added on top of C.

If you want to do go to big non-embedded applications, use Java, or C#

Both of these languages are so reliable and elegant they make C++ look like a messy bunch of crap, (not to be confused with 'c', which is great)

So to conlcude:

'C' good, low level, elegant, and popular

C# easy, powerful, reliable and popular

Java, easy, powerful, reliable and cross platform

C++ an obsolete and unreliable language.






Title: Re: best program to learn C++?
Post by: izua on June 29, 2008, 04:09:10 AM
C++ an obsolete and unreliable language.

exactly. C++ is crap. that's why it is the choice of major game design companies and the assumed language in almost any openGL tutorial, the language in which the php interpreter is programmed, the language on which most linux distros and the attached software comes programmed in. A
not to mention, most of the pseudocode out there follows a C++ structure (curly braces, pointer and object operators :P).

So, I guess that so many people use it just because they think it's good. They're wrong. Use Visual Basic. 3, if possible. If not, 2, or Qbasic. That's what Torvalds used to write its kernel.

I'd sugest you learn brainfuck (http://en.wikipedia.org/wiki/brainfuck) or lolcode (http://en.wikipedia.org/wiki/lolcode)
Title: Re: best program to learn C++?
Post by: BANE on June 29, 2008, 05:53:20 AM
Thanks, I think I'm going to get Brainf*ck and Lolcode both and try to learn them both while doing your mom..................... :D :D :D

No, not really, I have already downloaded BloodShed and seem to like well.

But thanks for all the helpful posts though ::)

Defiantly not Bane
Title: Re: best program to learn C++?
Post by: izua on June 29, 2008, 08:18:51 AM
Now, I haven't bashed you, (back at your mom, smartass)but I think the fact that you are offended by a name, or by my opinion, without any sustained argumentation, only expletives, pretty much proves a point.
Title: Re: best program to learn C++?
Post by: JesseWelling on June 30, 2008, 12:30:38 AM
C++ an obsolete and unreliable language.

Obsolete is a function of what you are doing. If you need a fast OO language you aren't going to beat C++ unless you write OO code in C, and even then you don't have all the flexibility that comes with OO such as virtual functions inheritance and operator overloading, you have to develop it your self. So yes I'd say for some widget on some desktop, or a client type program, Java and C# are pretty good. But for performance oriented application software, C++ is king.

As for Unreliable, How so? Java and C# run on virtual machine that must run on a OS. On top of that this virtual machine must also manage the memory of each program that is running. That's one more level of complexity, and that's supposed to be as reliable as pre-compiled code?

Java and C# are easier to use, not more reliable.

Title: Re: best program to learn C++?
Post by: Kagi on June 30, 2008, 08:26:27 PM
Personally I suggest getting a book from Deitel. I have always found their books to be very helpful and they are what i used to learn c/c++. you can get their c++ book for like ~$3 at http://product.half.ebay.com/C-How-to-Program_W0QQprZ2326681QQtgZinfo. I don't own their c++ book, but their old c version from the late ninties, but i'm sure it's still well written. On another note, half.com is a goldmine as far as cheap books go.
Title: Re: best program to learn C++?
Post by: Webbot on July 01, 2008, 06:36:38 PM
Quote
C++ an obsolete and unreliable language
Complete rubbish. No language is 'unreliable' - 'only programmers'.

Quote
Java and C# are easier to use, not more reliable.
Agree entirely. And would add that they are easier because they are more 'forgiving' - ie help to make up for your mistakes.
Title: Re: best program to learn C++?
Post by: BANE on July 01, 2008, 07:26:15 PM
Quote
Complete rubbish. No language is 'unreliable' - 'only programmers'.
the program is only as smart as the programmer
 :D
Bane
Title: Re: best program to learn C++?
Post by: Admin on July 20, 2008, 08:39:50 AM
Just be aware people that I will suspend those who flame. Don't let me see this again . . .


Use the language best for the job at hand . . .