Learning C++

Recommended Videos

Bug MuIdoon

New member
Mar 28, 2013
285
0
0
Hello fellow 'Pists, hope you're all good.

I've recently decided to teach myself some programming, or more specifically C++.
I'm fairly new to any kind of scripting, so it's going to be a new experience for me, but my goal is to (eventually) make myself a game.

I was just wondering, to the rest of you out there who have some experience in the field, are there any recommendations on where to begin? Any useful websites, or books that have helped you? Any ideas for small beginner's projects that will help me get to grips with C/C++?

Thanks for any help. Keep on escapin'!
 

TheYellowCellPhone

New member
Sep 26, 2009
8,617
0
0
Codeacademy.com has a course where every week for a year they send you (through email) lessons on progressing difficulty.

But that's in Java. It really doesn't hurt to understand one programming language before moving to another programming language. Python, for example, is a good beginner's language.
 

mitchell271

New member
Sep 3, 2010
1,457
0
0
C and Adagio are good jumping off points for coding and sprite based GUIs. I learned in my highschool, so I can't offer any resources for learning, but I will say this.

Make sure you learn in chunks. Don't go head first into complex calculations, class files and writing your own libraries, learn it step by step, no matter how great the temptation. Learn simple things like loops and arrays first while constantly learning how to use the proper syntax and whitespace. And for the love of god, use comments!

I don't remember much C++, but if you ever try C#, try this:

bool continue = TRUE;
int number = 0;

while (continue = TRUE)
{
number = rand.random(0,10);
Console.WriteLine("{0}", number);
}
 

SpAc3man

New member
Jul 26, 2009
1,197
0
0
I would highly recommend a book called "Thinking in C++". by Bruce Eckel. There are two volumes. Volume one is subtitled: "Introduction to Standard C++" and volume two is subtitled: "Practical Programming".
Start with volume one. The best part is Bruce Eckel has made his books available for free via download from his website.
Have a link to the downloads page [http://www.mindviewinc.com/Books/downloads.html]

These books were recommended as course readings by my university lecturer so they do hold very good merit.

I would also recommend a book called "An Introduction to Object-Oriented Programming" by Timothy Budd.
This is all about the object orientated programming design paradigm which is pretty much the standard way of using C++. The book covers the techniques in several programming languages but C++ is very prominent. Learning about object orientated programming would be extremely useful as it is used in almost all of the most popular languages and you will be forced to learn it at some point if you are going to be learn C++.

EDIT: I would also suggest Java as another language to consider. I recently started using it after using C and C++ for a couple of years and it is very nice to use. All the tools are free and there is a lot of content to help you learn online. Bruce Eckel has books on Java too.
I would only consider Python if you were looking at web development rather than application development. Python is a great language and is great for web development when using a framework like Django but I would not use it over C++ or Java for general applications.
 

DoPo

"You're not cleared for that."
Jan 30, 2012
8,665
0
0
mitchell271 said:
I don't remember much C++, but if you ever try C#, try this:

bool continue = TRUE;
int number = 0;

while (continue = TRUE)
{
number = rand.random(0,10);
Console.WriteLine("{0}", number);
}
That is a very odd piece of code. I get that it's an infinite loop but why do you have a variable set to true if you're not going to use it as an exit point? Also, even if you wanted to, you wouldn't be able, as you're assigning it to true on each iteration of the loop rather than checking. Well, at least that's what C/C++ would do, I'm not sure on the behaviour of C#, it might actually be an invalid syntax, at least it is in Java. You also have a container for the random number but it's not actually needed. Then again, I'm not sure if that's more efficient in C# or not but usually the compiler should optimise that code for you. Finally, I'm pretty sure that print statement is going to be less efficient as you'd need to construct the string in memory on each iteration (due to the substitution needed). Again, not an expert in C#, just seems that way. Here is a revised version:
Code:
while (TRUE)
{
Console.WriteLine(rand.random(0,10));
}
Shorter and might work better if my assumptions for C# are correct. You might want to put a sleep at the end of the loop so you can actually see the numbers it comes up with, though.

OT: You can try cplusplus.com [http://www.cplusplus.com/doc/tutorial/] it has a good set of tutorials and references for it. There is also Cprogramming [http://www.cprogramming.com/] but I've not used it and the same goes for cppreference [http://en.cppreference.com/w/]. As for books, there are two I was told of but never read - C++ In a Nutshell and C++ How to Program - both are suitable for beginners. Or at least they are advertised as such.

With that said, are you sure you want to make an entire game in C++? Because I recently looked at Unity and it's actually rather nice for development, the code you write can be in JavaScript, C# or Boo (appears to be an offshoot of Python) but you'll only be writing scripts that can be attached to object or actions but you don't really have to do that much coding, most of the rest is handled by Unity and that has a nice set of features. You can even get scripts from elsewhere, and there is an asset store for...well, assets. A lot of them free, too. Unity itself is free and you can use it for whatever.
 

Bug MuIdoon

New member
Mar 28, 2013
285
0
0
SpAc3man said:
I would highly recommend a book called "Thinking in C++". by Bruce Eckel. There are two volumes. Volume one is subtitled: "Introduction to Standard C++" and volume two is subtitled: "Practical Programming".
Start with volume one. The best part is Bruce Eckel has made his books available for free via download from his website.
Have a link to the downloads page [http://www.mindviewinc.com/Books/downloads.html]

I would also recommend a book called "An Introduction to Object-Oriented Programming" by Timothy Budd.
This is all about the object orientated programming design paradigm which is pretty much the standard way of using C++. The book covers the techniques in several programming languages but C++ is very prominent. Learning about object orientated programming would be extremely useful as it is used in almost all of the most popular languages and you will be forced to learn it at some point if you are going to be learn C++.
Kudos for that! Downloaded both those volumes, and will be getting all the info lodged in my head over the next few weeks.
I'll definitely check out the other book too at some point. Don't want to bite off more than I can chew just yet though.

DoPo said:
OT: You can try cplusplus.com [http://www.cplusplus.com/doc/tutorial/] it has a good set of tutorials and references for it. There is also Cprogramming [http://www.cprogramming.com/] but I've not used it and the same goes for cppreference [http://en.cppreference.com/w/].

With that said, are you sure you want to make an entire game in C++? Because I recently looked at Unity and it's actually rather nice for development, the code you write can be in JavaScript, C# or Boo (appears to be an offshoot of Python) but you'll only be writing scripts that can be attached to object or actions but you don't really have to do that much coding, most of the rest is handled by Unity and that has a nice set of features. You can even get scripts from elsewhere, and there is an asset store for...well, assets. A lot of them free, too. Unity itself is free and you can use it for whatever.
Thanks for the url links, I've been using cprogramming.com over the past few days, and drilling all it's tutorials in to my brian. They've been quite nib friendly so far, and I'm actually finding it a lot less confusing than I thought I would. I'll check out the other 2 sites.

I should maybe have rephrased my post. My goal is not to 'make a game'. Learning C++ is predominantly my goal. Making a game is just the goal for my learning, if you catch my drift. I've played games for over 20 years, and have helped make games/mods before (but more so on the design/graphics side) so I'm just setting that as my ideal for "Yeah, you've learned this now!" I'm learning C++ because I really want to learn a strong language, and C++ is just the standard nowadays for many, many things, not just games. I was/still am extremely torn between learning C++ and C# though.

On a side note, Unity is nice, I agree. I worked with some guys earlier this year making a hand-drawn game/music video using Unity and it was heaps of fun to do!
 

DoPo

"You're not cleared for that."
Jan 30, 2012
8,665
0
0
Bug MuIdoon said:
I'm learning C++ because I really want to learn a strong language, and C++ is just the standard nowadays for many, many things, not just games.
Eh, different tools for different jobs. C++ is nice and all but it's not always the solution. It gets applied slightly too often though. C++ is great if you're generally after performance in the long run rather than development time, essentially when the CPU cycles are more valuable to you than development. But in lots of cases you are not really too bothered by the program taking extra few milliseconds to finish a task, besides "throw more hardware at it" is an option, but you do want to manage complexity and that can be hard with C++, as it's great for giving you control over lower level stuff and it has lots of flexibility but at the cost of higher level functionality being a bit hampered. Sometimes you do have to say, "OK, I'm done with microptimisations, I really have to get this easier to manage". And other times you're fine with slightly increased complexity. It's not a hammer and nail situation, there are lots of tools available. Only, perhaps in C++'s case it's a Swiss knife and problems but sometimes you need only an actual screwdriver rather than a folded one along with a knife and a spoon.

Bug MuIdoon said:
I was/still am extremely torn between learning C++ and C# though.
Despite the name, C# is not really that close to C/C++. It's really similar to Java, though, it's pretty much Java but done in the Microsoft way. It's...OK, as far as I've used it. I didn't learn much of it, since I knew Java so it was a matter of just applying some slightly altered syntax on a couple of places and that was pretty much it, but its strength lies in being part of the .NET family. As a programming language...it works, what can I say, there are some neat stuff like shortening the setter/getter invocations and some syntactic sugar but not much of an advantage (or disadvantage) over other languages. As part of .NET, however, it's quite nice. The downside I see with it is that there aren't a lot of IDEs for C# - Visual Studio and MonoDevelop are the ones I know of. On the other hand, I used Visual Studio and it's nice, I'd certainly recommend it for .NET stuff.

If you want my opinion, out of those two, I'd suggest going with C# - it should be easier for beginners to pick up than C++. Once you're not a beginner in programming any more, take a look at C++ and other languages. Once you know one, it should be really faster to learn others - the syntax is mostly the same, function invocations and language constructs, too. Actually, Python may be easier to get into than both of those, it has less features, so it should be even easier to start learning programming. You could, if you wish, start off with than then move on to the others. here [http://lifehacker.com/how-i-taught-myself-to-code-in-eight-weeks-511615189] is a how to on how to learn Python. It's more web development oriented but you can skip those parts.
 

Angie7F

WiseGurl
Nov 11, 2011
1,704
0
0
For some weird reason, I think I will have to learn basic stuff for work.
I was just going to join an online course or something...
 

mitchell271

New member
Sep 3, 2010
1,457
0
0
DoPo said:
That is a very odd piece of code. I get that it's an infinite loop but why do you have a variable set to true if you're not going to use it as an exit point? Also, even if you wanted to, you wouldn't be able, as you're assigning it to true on each iteration of the loop rather than checking. Well, at least that's what C/C++ would do, I'm not sure on the behaviour of C#, it might actually be an invalid syntax, at least it is in Java. You also have a container for the random number but it's not actually needed. Then again, I'm not sure if that's more efficient in C# or not but usually the compiler should optimise that code for you. Finally, I'm pretty sure that print statement is going to be less efficient as you'd need to construct the string in memory on each iteration (due to the substitution needed). Again, not an expert in C#, just seems that way. Here is a revised version:
Code:
while (TRUE)
{
Console.WriteLine(rand.random(0,10));
}
Shorter and might work better if my assumptions for C# are correct. You might want to put a sleep at the end of the loop so you can actually see the numbers it comes up with, though.
That's kind of the joke. He be stuck in an infinite loop where it constantly prints numbers across the terminal. Then we sit back and watch the hilarity ensue. Your revised version is definitely easier, I hadn't thought of doing it that way. In my defense, it was late and I was tired! XD Also, didn't know about the code tag. I'll definitely use that in future.
 

Pinkamena

Stuck in a vortex of sexy horses
Jun 27, 2011
2,371
0
0
Just... Don't. I had a course this semester on C++ (more specifically it was data acquisition and visualization using ROOT), and I had already had two courses on Java and Python. It was a fucking nightmare, and I hope I will never have to use that language again. It's REALLY unforgiving.
 

Davey Woo

New member
Jan 9, 2009
2,468
0
0
http://www.wibit.net/curriculum/the_c_lineage/programming_cpp
I passed my C++ module at uni thanks to these guys. They goof around a bit but it really did help me learn the very basics of C++.

I think for making your own game you might be better off directly learning a game engine instead of learning C++ first. Unreal Development Kit and Unity are both free for non-commercial use, if I remember correctly.
 

Eldritch Warlord

New member
Jun 6, 2008
2,901
0
0
http://www.cpp-cookbook.com/

These programmer's cookbooks are pretty good, I've got one for iOS development and my brother has one for PHP/JavaScript/SQL and we're satisfied with them. If you don't already know the basics of programming though I'd recommend taking a course or two in it. Not necessarily C++, but some object-oriented language.
 

Megacherv

Kinect Development Sucks...
Sep 24, 2008
2,650
0
0
Bug MuIdoon said:
Hello fellow 'Pists, hope you're all good.

I've recently decided to teach myself some programming, or more specifically C++.
I'm fairly new to any kind of scripting, so it's going to be a new experience for me, but my goal is to (eventually) make myself a game.

I was just wondering, to the rest of you out there who have some experience in the field, are there any recommendations on where to begin? Any useful websites, or books that have helped you? Any ideas for small beginner's projects that will help me get to grips with C/C++?

Thanks for any help. Keep on escapin'!
Please don't call it 'scripting', that term is offensive to us programmers :p

Anyway, cplusplus.com is a good place for reference, MSDN is also a good resource as well and is free to everyone (You should see if you're eligible for Microsoft DreamSpark, get hooked up with Visual Studio 2010 for free legally :D).

My advice would actually to be learn C# first (www.csharpcourse.com has a brilliant book to learn C# with, written by one of my lecturers), much easier language to learn but is still C-based so it'll get you into the C mindset, and Visual Studio's IntelliSense will help you along the way (just don't become too reliant on it). C and C++ are quite scary to jump into and asks a lot from the programmer (e.g. you have to delete objects from memory yourself and it requries you to know how your code affects the processor).
 

Headsprouter

Monster Befriender
Legacy
Nov 19, 2010
8,662
3
43
I want to learn C++ independently this summer so I can maybe help out with Timesplitters: Rewind. It'd be dream! Maybe a little bit of animation, too. Might be cool.
 

Generic4me

New member
Oct 10, 2012
116
0
0
I wouldn't recommend C++ as a beginner language, it's pretty brutal. If there's any language you shouldn't attempt to learn first, it's C++.

Of course, you're not going to listen to me, so here:
http://www.youtube.com/watch?v=tyVhn0FWWB4 For 99.99999% of the general population
http://www.Xoax.net/ is a good place too, but it's harder.
 

mKeRix

May contain sarcasm
Oct 17, 2010
65
0
0
If your goal is to make a game, I'd really recommend you to go with Unity or GameMaker Studio instead. Which one of those two depends on what you want to create and for which platforms. While GameMaker is definitely easier to learn, it will probably start to be pretty limited once you go into 3D games (although I never tried that out with their engine, maybe you can check out their official forums).
You find a lot of support for both engines, especially Unity. Just check them out and choose.

Also, if you really want to go with C++, check out Visual Studio as an editor. Brilliant software.
 

DoPo

"You're not cleared for that."
Jan 30, 2012
8,665
0
0
Pinkamena said:
Just... Don't. I had a course this semester on C++ (more specifically it was data acquisition and visualization using ROOT), and I had already had two courses on Java and Python. It was a fucking nightmare, and I hope I will never have to use that language again. It's REALLY unforgiving.
Yeah, I suppose it is for beginners. Let me pick an absolutely random quote here.

Bjarne Stroustrup said:
C makes it easy to shoot yourself in the foot. C++ makes it harder, but when you do, you blow away your whole leg!
This Bjarne guy seems to agree. And I think we can count him as a not-beginner, so it probably applies for advanced users, too.

mitchell271 said:
That's kind of the joke. He be stuck in an infinite loop where it constantly prints numbers across the terminal. Then we sit back and watch the hilarity ensue.
Well, until you press Ctrl+C or close the terminal. But at any rate, why not just give him a fork bomb? That's going to be way more fun.
 

ASnogarD

New member
Jul 2, 2009
525
0
0
Ahhh, learning C++ to make games, I am on that rocky road myself so heres a few things I learnt...

- Need to learn the basics of C++, and its boring as hell just stick to it as its essential. All that crap about pointers and classes , inheritance and polymorphism, streams and standards... you need 'em all. Dont be discouraged as once you cross the basics the rest gets a lot more interesting and fun.

- Pick a API and play with 2D, get that 3D MMOFPSRPGWOWKILLERAPP out your head, its a long road to 3D and 2D is plenty to get to grips with. The most common ones are SDL and SFML.

- Start off small scale and build up a set of 'tools' you can reuse, things like a basic rendering class and initiation class, stuff to help get text to the screen, perhaps a mode selection/cycle system (to get from intro - main menu - game - credit - outro)... all this stuff is great practise and it can be taken to other projects, and can be enhanced and improved as you improve. Saves a lot of time if you dont need to re-write the code to initiate the API's and screen.

- DONT try build a 'engine' early on, your collection of reusable code will grow on its own as you work on your projects so dont make the common mistake of building an 'engine' to do all your games on... it sounds cool and a good idea but believe me its mostly a waste of time early on. Just do the code you need to get your current project going, then when you are done you can take parts of the code for your next project.

- You can step up from 2D to 3D with a API like OpenGL and some helper API's like FreeGLUT. SDL and SFML also have OpenGL support. You dont need to go full on 3D initially either, just use the hardware acceleration of OpenGL to project your game on a 2D plane as you learn.

In short, master the basics, dont be in a rush to get to your master game plan, take it in steps... small steps with small victories is encouraging, a huge step is tedious and discouraging especially if the reward ends up being tiny.
( I spent 4 - 6 months coding a game with a 4 way scrolling screen, a animated hero sprite I drew myself, etc etc etc... all for 75 views and about 15 downloads and about 7 comments... and thats about normal for all new game programmers, you need to build up to and half way decent releases ).