Newbie's Guides to C/C++ ?

CrimandEvil

Dick with a heart of gold
Joined
Oct 22, 2003
Messages
19,670
I want to start learning C/C++ but where are some good guides to learn? I have one of those "C++ in a Nutshell" books (I think, I'll have to check my book shelve) but I want some more guides to help me learn. Thanks!
 
C and C++ are about as similar as the Kon Tiki and the USS Nimitz. Yeah, both float on water.

I highly suggest you learn C++ first. Modern, Standard C++.

> where are some good guides to learn?

Most importantly, you need a good compiler.

The following are examples of good compilers:
gcc 3.3.3 (GCC is the GNU Compiler Collection)
MSVC .NET 2003 (the Microsoft Visual C++ Compiler)

You can get gcc 3.3.3 for Windows by downloading my MinGW distro - a complete compiler, development toolchain, and lots of precompiled libraries and utilities, all installable within seconds and packed into a dozen megs. Or you can shell out the bling bling for MSVC.

The following are examples of bad compilers:
gcc 2.x, 3.0.x, 3.1.x, 3.2.x (2.x is really, really bad, the early 3s are kinda crufty)
MSVC .NET before 2003 (very bad)
MSVC 6 (absolutely atrocious)

As for books:

_C++ Primer Plus, 4th Edition_ by Stephen Prata is a good introduction to the language.

_The C++ Programming Language, Special (or 3rd) Edition_ by Bjarne Stroustrup is a bit more advanced, but also more comprehensive. It'll serve as a useful reference when you become comfortable with the language.

The C++ Standard itself, 14882 2003, is available in PDF form for $18 dollars; you pay by credit card and can download it immediately. It's an even better reference than Stroustrup, in some ways, and even worse to learn from.

_C++ FAQs, 2nd Edition_ by Cline, Lomow, and Girou is an excellent morality guide, and pretty comprehensive.

_Effective C++, Second Edition_, _More Effective C++_, and _Effective STL_ by Scott Meyers are also excellent, indispensible morality guides.

_Exceptional C++_ and _More Exceptional C++_ by Herb Sutter are pretty useful, but I like Meyers' books better.

_Modern C++ Design_ by Andrei Alexandrescu is an advanced text that you'll want to get when you become bored with the others.

_C++ Templates: The Complete Guide_ by Vandevoorde and Josuttis is comprehensive and more detailed than anything else I mention here. Obviously it only covers templates, but templates are where it's at anyways.

Also,

NEVER READ ANYTHING WRITTEN BY A MAN NAMED HERBERT SCHILDT.
 
Also, good C++ programmers like ithil (when he's not drunk), Uller (when he's not drunk), and myself (when I'm not drunk) hang out in the IRC channel mentioned in my signature. We also have several people learning C++, or at least saying they're learning C++.
 
I have Dev C++ and MiniGW so I'm sure one of them has GCC with it. I'll check out the books too (have to head towards the library, theres a cute librarian there :D), I hate IRC but I'll check it out too. For the sake of not having much money are there any good ones online?
 
_The C++ Programming Language, Special (or 3rd) Edition_ by Bjarne Stroustrup is a bit more advanced, but also more comprehensive. It'll serve as a useful reference when you become comfortable with the language.
I've got this book and I agree that it's a very useful reference for those who really wish to program in C++. Definitely recommended.

As far as free online references go, there are some reasonable resources, but you'll really want to use a dead tree version.

You got any experience with other programming languages?
 
[CrimandEvil]
> I have Dev C++

Which is an IDE.

I don't believe in IDEs, but maybe you like them.

In contrast, MinGW is just a port of gcc.

> For the sake of not having much money are there any good ones
> online?

Nothing comprehensive that I have ever found. I want to write my own C++ page, but I haven't found the time yet.

[Elledan]
> You got any experience with other programming languages?

Hopefully the answer is "no". ;-)
 
The last time I programmed was like ten years ago in middle school (I'm 21 now) and that was either fortan, basic, perl or python, not sure. My hacker friends and I would get together and write scripts to use on the Macs at school, hardly remember any of it so its pretty much a blank slate. I like to start off with an IDE because it helps me learn all of the basic stuff fast. When I learned basic HTML in under three hours I used an IDE for it. After that it I could figure out how to do the advance stuff by code and thats how I do it now.
 
[CrimandEvil]
> hardly remember any of it so its pretty much a blank slate.

Good. Anything you do remember, forget. ;-)

> I like to start off with an IDE because it helps me learn all of
> the basic stuff fast.

I strongly advise against this.

Developing in straight MinGW is really easy. Why, you just create text files (with Metapad or your favorite text editor), and then you go compile on the command line. If you want to automate compilation, you learn how to use the program "make".

That way, you learn about the relationships between files, and separate compilation, and all of that.
 
Originally posted by STL
NEVER READ ANYTHING WRITTEN BY A MAN NAMED HERBERT SCHILDT.

That's what pretty much everyone around here seems to say. I've never read the guy's stuff, so I don't know how he is, but what is so bad about Herbert Schildt?
 
Originally posted by UralTerpsichore
That's what pretty much everyone around here seems to say. I've never read the guy's stuff, so I don't know how he is, but what is so bad about Herbert Schildt?

I haven't read any of the guy's work either, but http://www.accu.org/bookreviews/public/reviews/0au/s.htm seems to agree with this forum's opinion of him. His books don't seem to be very well recommended, and after reading a couple of the reviews, I couldn't help but laugh.~
 
Originally posted by STL
C and C++ are about as similar as the Kon Tiki and the USS Nimitz. Yeah, both float on water.

I highly suggest you learn C++ first. Modern, Standard C++.

I hear people saying this all the time, and I'm sure it does work well for most people.

I just want to toss in my experiences here.

I learned C++ and didn't really like it at all, it seemed overly-complex and inefficient.
So I decided to learn C*. I got pretty proficient in C and now I'm going back to learning C++. By learning C I understood more about its benefits and limitations, as well as why C++ does make sense for many programs.

So, while learning C++ first is probably best for most people, there's also something to be said for learning C.

*I started with O'Reilly's Practical C Programming (the cow book), and highly reccommed it to anyone wanting to learn C.
 
[RazeDS]
> So, while learning C++ first is probably best for most people,
> there's also something to be said for learning C.

I learned C first as well, based on a distrust of C++. It worked for me, but probably wasn't an optimal use of my time. I also didn't get very in-depth; my first program was SHA-1, and I got frustrated with allocating memory in my second program.

C++ is a big language, that's for sure. I've been using it for over 2 years now and I still couldn't tell you what two-stage name lookup is, or the first thing about locales. And parts of C++ are indubitably crufty (some bonehead parts of std::string and templates, for example). But it also enables a very elegant style of programming that uses the programmer's time efficiently, and usually results in very high performance code.

For example, using functors is usually faster than the C technique of function pointers, due to inlining.

I therefore strongly recommend against people learning C before C++. I mean, you could always start off with C++ as a better C.
 
Originally posted by STL

I therefore strongly recommend against people learning C before C++. I mean, you could always start off with C++ as a better C.

That's what my professors said too. I guess the problem I had was that no one really explained why C++ works the way it does. They would just say "it's object oriented, so you do it like this, group this here and make this a private function".

So maybe my problem wasn't so much with C++ but the way the books and professors i had taught it. I wanted to understand why it was better to do things the way C++ did them. By going back and learning C, I caught myself thinking "You know it would be a lot easier if I could just <something very similar to the C++ method of accomplishing what I was working on>". So it gave me an understanding of why C++ works the way it does, I guess that's all I'm saying.

I do agree with you that C++ generally uses the programmer's time more effeciently, and for most people they're better off starting with C++. For me personally (and obviously others with my learning style), it worked a lot better learning C first, because it made me appreciate and understand how C++ works.
 
[RazeDS]
> I guess the problem I had was that no one really explained why C++
> works the way it does.

That's because few people really understand the C++ philosophy.

> They would just say "it's object oriented, so you do it like this,
> group this here and make this a private function".

Gaah. C++ is not just an "object oriented" language. That's not even the coolest part of it. Of course, C++ has covariance, which Java (supposedly a "purer" OO language) lacks.

Anyone who teaches C++ without teaching templates isn't a good teacher.

> So maybe my problem wasn't so much with C++ but the way the books
> and professors i had taught it.

Professors by and large teach C++ incompetently. :-P
 
you know.. I love templates to death... but OH THE DEBUGGING PAINS!

anyways, on topic... I've gone through a slew of c++ books in my time, and oddly enough, one of the best ones I've found it Teach youself c++ in 21 days. Except for one thing. It does an absolutely terrible job of explaining objects IMO. And I personally think it introduces them too early. I have found that having a strong backgroung in C and other procedural languages helped my c++ learning immensly. Once you have a workign knowledge of C, you have the tools to open your mindset that is the glory of OOP. The problem with books that teach you OOP right away, is that you might not understand some of the advanced C-like stuff that they will teach you as you might still be grasping at OOP concepts. So find a recommendation on a good C book... learn c... then dive into objects. After knowing objects and pointers, the rest of C++ just seems to make sense. Templating is a great tool... and theres a bunch more too. If you want to avoid some of the C++ pains you might experience, I'd also suggest learning C# first. The syntax of C# closely parallels c++, but theres a garbage collector, and some other cool things (foreach is my friend :) ) Then you can jump back to C++ with a good basis in OOP and start learning abotu pointers, polymorphism and its power. Anyways.. I probably rambled a but much hear, but its near quitting time and Im tired.. so hopefully 1 or two sentances in this made sense for you :)
 
[schapman]
> you know.. I love templates to death... but OH THE DEBUGGING PAINS!

Yeah, I just encountered some Boost Function shadow warnings that generated hundreds of lines of text (for only two warnings). Fortunately, once you've seen one shadow warning, you've seen them all, and I immediately dispached a message to the Boost list.

> So find a recommendation on a good C book... learn c... then dive
> into objects.

I still strongly recommend against this.

The basics of objects are pretty easy. You can start off with structs, and then move to structs with constructors, and go from there.

> If you want to avoid some of the C++ pains you might experience,
> I'd also suggest learning C# first.

Buh.

C# /doesn't/ have templates, /doesn't/ have comprehensive creation/destruction semantics - it's probably good at out-Javaing Java, but that's not the point.

> (foreach is my friend )

The STL owns such constructs. ;-)
 
oh yeah.. I was SUCH a happy camper when I learned about the STL.. so much work done for me (and probably better than I could do).

I suggested C# only as a basis only because you don't have some of the worries of c++ (like memory leaks). I think it would be a good basis for c++, when you relaize the extra power of C++. I'm stuck w/ c# at work right now, and I miss my pointers, templating, and some of the other cool things from C++.
 
> I suggested C# only as a basis only because you don't have some of
> the worries of c++ (like memory leaks).

Memory leaks are not a problem in proper C++. Period. In correctly designed programs, the worst memory leaks will occur in buggy resource managers. When identified and fixed, all uses of the resource managers will be fixed.

Maybe I should write a book... New Considered Harmful.
 
I'm just thinking that is great if everyone starts programming properly in the first place, but most don't. So by having a garbage collector come around once in a while (btw.. i dont like the idea of auto garbage collection either), it might make some of the fundemental concepts of c++ easier. People might get discouraged when they start tanking stuff cause of overruns and leaks.

btw... read a bunch of your page.. I like pretty much all of your points :) you should write a book.

The only thing I disagree with is the usefullness of inheritance. I come from a game development background, and inheritance can be very usefull then. If you think about everything that has to render and how things render, its a good way to share functionality across objects.

ex.
if you are writing in openGl and directx, you can have your object inherit a renderer object that is written for openGL or directx depending on settings loaded. Or if you maintain a list of objects that need to render, having one object that has some pure virtual required members, means that others workign on your project can see that there are certain functions they must implement to create new types into your engine. Even things like Room objects, which can act like nodes linking to each other is a good place to use an abstract base for. Anyways.. just ranting cause I'm temporarily bored at work.. and I'm assuming you know all about the best uses for inheritance and such.. but you never know, someone else might like my ideas ;)
 
[schapman]
> I'm just thinking that is great if everyone starts programming
> properly in the first place, but most don't.

Hey, I started out by managing my own memory (in C) and then trying to reimplement something that looked like std::vector (in my first 6 months of C++). I learned.

> So by having a garbage collector come around once in a while (btw..
> i dont like the idea of auto garbage collection either), it might
> make some of the fundemental concepts of c++ easier.

I've seen people who use garbage collectors, and then they can't see any other way to do things. Sad, really.

> The only thing I disagree with is the usefullness of inheritance. I
> come from a game development background, and inheritance can be
> very usefull then.

When inheritance is useful, it's very useful; there's a reason it's a part of the language. But inheritance should not be used everywhere.
 
STL, I read half of Effective C++ by Meyers today... thanks for the recommendation, definitely a great read... as he was going through all these examples I felt as if I should start over from scratch (for the 3rd time), not to mention providing answers as to why certain combinations of const and & in function declarations worked and others didn't, where I had to figure this out in college by guessing and compiling and debugging... =P

And that was just the first half of the book... so I'm going to finish reading it before I start coding again =P

I also managed to pick up a few cheap books at Half-Priced Books, maybe you've had experience with these?

The Waite Group's "Object-Oriented Programming in C++"
The Waite Group's "C++ Primer Plus"
Shtern's "Core C++: A software engineering approach"
Holzner's "C++ Black Book"

At less than 10 dollars apiece I figure it couldn't hurt to pick them up...
 
Don't buy old C++ books. It certainly CAN hurt to read them. As a general rule, if the book was written in the twentieth century, view it with suspicion. There are some good pre-Standardization books, but not many.

I know what C++ Primer Plus 4th Edition by Stephen Prata is. Don't know what the rest of those are.

You do have Effective C++ /Second Edition/, right? ^_^
 
Holzner's "C++ Black Book"
I have that book around here somewhere. It isn't that bad of a book, just kinda bothered me that he named the beginning of the chapters "In Depth" but yet he doesn't go In Depth until the "Immediate Solutions" part of the chapter.

But I'd much rather read C++ Primer Plus. It's just more fun to read. Plus, the C++ Primer Plus has questions and answers at the end, along with Programming Exercises, so you can make sure you understand the material.
 
D'oh, the Prata's C++ Primer Plus is the 3rd edition published in 1998. Lafore's Object Oriented Programming in C++ was published in 1999. But, both cover Standard C++.

The Core C++ was published in 2000 but it looks like it does not cover Standard C++ as it doesn't mention either the built in string class or Standard C++ at all. And it's out of print now, with only one edition ever published. Wow, I guess that one's no good. Thank goodness for receipts...

C++ Black Book was published in 2001, and looks quite decent actually, except for the fact that his int main()'s have "return 0;"? =P

Yes, the Effective C++ is the 2nd Edition version.... I think I'll be ordering these online but reading them at B&N till they get in... =P
 
[Jerry]
> D'oh, the Prata's C++ Primer Plus is the 3rd edition published in
> 1998.

Mlar. Get the 4th edition. (Which still talks too much about old compilers, but eh, what are you doing to do.)

> Lafore's Object Oriented Programming in C++ was published in 1999.
> But, both cover Standard C++.

The Standard was released in 1998, true, but good compilers were not released until 2001 (gcc 3.0), or 2003 if you live in MSVC land (.NET 2003). I'm ignoring all of that EDG stuff, because I don't know those compilers, and they're not as popular as gcc/MSVC.

> The Core C++ was published in 2000 but it looks like it does not
> cover Standard C++ as it doesn't mention either the built in string
> class or Standard C++ at all.

Uggggh.

std::string sucks, but it sucks a lot less than non-Standard string classes.

> C++ Black Book was published in 2001, and looks quite decent
> actually, except for the fact that his int main()'s have
> "return 0;"? =P

Style thing. Lots of people have bad style. Including return 0; is a pretty minor style problem. "void main" indicates a deep misunderstanding of what a Standard is.
 
Back
Top