• ### Announcements

#### Archived

This topic is now archived and is closed to further replies.

# How did you guys learn C++ ?

## Recommended Posts

HTML    151
Hey, I am having trouble learning C++, I am not sure what I am doing wrong. I do not currently have a good C++ book, but will be getting one soon. I have Visual C++ 6, Sams teach your self C in 24hrs though. I am taking the ones online instead because I don't want to really learn C and the Visual C++ 6 book is geared more towards MS Visual C++, but I am using KDevelop. But, my question is, how did you guys learn it ? I sit and read the chapter over and over on variables and I can barely understand it.(all I can do is make, "My first C++ program" appear on the screen without any notes or books. And copy code from the book) I have tried taking them in the past. hen I tried again now for about a week. (but I have actually tried many more times than that, so in all, maybe a few months.) I want to learn how to program games in C++ so should I take game tutorials while I am learning C++ or after? Thanks in advance for replies. [edited by - HTML on October 12, 2003 4:26:47 PM]

##### Share on other sites
Mscgamer    286
Are you in high school? If you are, you should consider checking to see if there are any programming classes at your school. If you''re not in high school, try a community college. Some people can''t learn from just looking at a book; you might need help that only a teacher can provide.

Just my two cents.

##### Share on other sites
twix    636
If you can''t handle variables yet, forget about making games for a while.

Come up with some questions about the variables chapter, and ask them here. If you tell us exactly what you don''t understand, we can probably explain it for you.

As for how I learned C++, I read a book and made some programs. There wasn''t really much to it.

##### Share on other sites
Before I say anything else, dont even think about making games. Concentrate on learning the syntax and how to do things in a console.

That being said, go to www.cprogramming.com and go through their tutorials. Those tutorials helped me more than any others. If you have money for a book, I would suggest Sams Teach Yourself C++ in 21 Days, which is freely available on the internet (not illegally, either). I think there is another, "Thinking in C++", that comes recommended and is also freely available.

What exactly about variables is giving you trouble? Manipulating them? Using them? Testing them? Knowing which type holds what? We''re here to help.

##### Share on other sites
Guest Anonymous Poster
I don''t know if you''ve already taken algebra or not but I seriously recommend you learn a bit of algebra. I am almost positive that if you understand algebra, you will have no problems understanding the concepts of variables and how to use them.
As for how I learned C++, I wasn''t able to motivate myself to read a book I had bought and go through all the examples so I decided to enroll in a class in a community college (quite a few years ago ), and that helped me to jumpstart. I had no problems going beyond the lessons after that on my own with the help of books.

Good Luck.

##### Share on other sites
Guest Anonymous Poster
quote:
Original post by HTML
How did you guys learn C++ ?

Personally, I bought a book and started reading it, utterly confused. Then I copied code from the book without really understanding how it worked. Eventually, just for fun, I started changing the sample code into something completely different and suddenly realized: "Hey, I''m programming!". After that initial bump, everything got easy for a while. That is, until the next bump. And so on.
quote:

I want to learn how to program games in C++ so should I take game tutorials while I am learning C++

Might work, but it''s probably a good idea to learn the language basics first. Do the excercises in the book. Take your time, don''t rush.

##### Share on other sites
Haytil    525
I picked up "C++ for Dummies" by Randy Davis. It was only $25, with CD, not$50, like most programming books. (Those prices are uncalled for).

Most "For Dummies" books kind of suck, but this one was surprisingly good. It covered almost all of the C++ topics you need to do any game programming, including complicated stuff like multiple inheritance, virtual functions, operator overloading, and so on. It was also very easy to understand.

The book came with the GNU compiler, but if you already have MSVC, it has instructions for that compileter as well.

It took me a while to go through it, as stuff like work came up, making me put the book down. But I rarely had problems understanding what was going on. If you do, put the book down for a few days, then come back to it.

Once I finished this book, it was easy to pick up a book focused on Game programming and understand everything it was talking about.

##### Share on other sites
fillipe    122
Yeah, if you could put up some questions about what specifically you are having trouble with, most of us could be of greater help.

There are some general advices though: attend some programming class, learn how the computer works, try some easier language first [ever tried C? Basic? Any scripting language?], search the web. Keep it simple [meaning, forget games until you're done with C++]. And just don't give up because it is becoming hard and obscure. The rewards are worth all the sweat.

A somewhat useful online tutorial on C++:

A good book on basic computer architecture:
Structured Computer Organization - Andrew S. Tannembaum

--
Andre Fillipe
(bhzkun AT yahoo DOT co DOT jp)

[edited by - fillipe on October 12, 2003 5:29:03 PM]

##### Share on other sites
ShinAli    122
I would suggest the book "Learn to Program with C++" by John Smiley, absolutely wonderful book. It has a slight mix of fictional story in it, as its set in a classrmom setting, with ''students'' asking questions on the material. It''s a really effective book.

Or, if you got some scratch, you could go for the ''Intro to Game Programming'' course on GameInstitute. I''m enjoying it so far.

And, as some people said before, experimenting with code helps alot, too.

P.S. - If you are able to take a live class in C++ programming, do that instead.

##### Share on other sites
HTML    151
Wow, thanks for such quick replies.

Yes, I know algerabra. My mistake,
I understand variables like:

a = 5;
b = 3;
result = a + b;

and that kind of stuff, but right now,
I am struggleing with this tutorial:

http://cplusplus.com/doc/tutorial/tut1-2.html

I understand almost everything in the tutorial
up to identifiers, then I am lost. I understand
what it is, but not when to use it and where.

Then data types.....I don''t understand why you
can''t just use "long" all the time if it has almost
all the numbers you need.

Then I don''t understand "declaring variables"
ex: unsigned short NumberOfSons;
signed int MyAccountBalance;
Initialization of variables(dont get those)

Then the rest just loses me...It might be because
I am bad at math. I never understand it until
after the test....kind of sucks...

Then the first part of operators looks easy, like:
+ / - * and then doing stuff like:
a++=b.

I don''t understand other simple things like void main()
and int main() and return 0 looses me too...

As for me learning other languages, I know most of html,
except when I got to the end of the book for templates and
stuff..but html was boring so I stopped. I tried C, but previously
looking at C++, it started to confuse me. Besides that, I like how
C++ has classes.

Oh, and when I took that gametutorial.com thing for the text game,
it seemed like they made a lot of their own stuff up like:
strRoomNorth, STILL_PLAYING, void DisplayRoom,
GetRoomInfo...ect. How do you do stuff like that?

Thanks so much again for your help, sorry if I wrote too much...

##### Share on other sites
liquiddark    350
quote:
Original post by matt_j
I learned C++ from this awesome book by this awesome author:
Teach Yourself C++, 3rd ed. by Herbert Schildt.

Take a look before you buy Schildt books

No offense, but he has a pretty horrible reputation.

ld

##### Share on other sites
Mr Grinch    318
First off, don''t get discouraged. Some people really get a handle on basic programming really fast, other people take longer. It took me a long time before I really got the hang of it. I think what works the best is if you can find someone to talk to about it. Then you can show him/her what you are trying, or even work through a chapter together. He/she can explain the stuff the book doesn''t cover well and expand on what they do cover well. That''s what I''ve found most helpful. If you can''t find someone, just try to work through some tutorials or books, and ask questions here. Anyway, good luck, don''t give up!

##### Share on other sites
quote:
Original post by HTML
I understand what it is, but not when to use it and where.

Variables are just used to store data. A variable''s name is its identifier. You manipulate variables to do what you want. You use them everwhere, because they''re like "handles" on pieces of data.
quote:

Then data types.....I don''t understand why you
can''t just use "long" all the time if it has almost
all the numbers you need.

You can use long most of the time. However, other types have built-in functionality that helps you deal with different types of data. Fundamentally speaking, there are only two types of data: floating-point and integral (and even that distinction is artificial).

The reason you have bools is to be able to easily and "safely" test the "truth" of an expression (if you don''t understand expressions and Boolean logic, google them up and have a read. That stuff''s all really important.

The reason for floats and doubles is to store fractional numbers. If you know something won''t be a whole number, use a float or double to represent it (btw, a double is basically just a bigger float, effectively. We''ll deal with size distinctions in a few moments).

If you know something will be whole, use an integer of some type. At this point, the only distinction between the different types of integers (besides signedness, which we''ll also get to in a minute) is their "capacity" - an int is the same thing as a long (on any compiler you''ll be using; it''s not rigidly defined that way by the Standard though)- they can each hold any number between -2.2 billion to 2.2 billion (roughly; the actual number is +/- 2^31).

If you want to store "strings" (all text counts in this area), use chars. A single char can store the ASCII (google it) value of any character, like ''a'', ''?'', or ''5'' (NOTE: ''5'' is not the same as the number 5). An array of chars can store a string like "My name is George." Of course, this is a little bit advanced, but you''ll learn in time how to use char*''s.

So, that''s a rundown of the basic types. Now, the two other issues: size distinctions and signedness.

Variable sizes are typically considered in either bits or bytes. A bit is a 1 or 0, the smallest meaningful piece of data. A byte is composed of 8 bits. A char, being the smallest basic data type, is a byte in size. A long (on any compiler you''ll be using) is 32 bits (4 bytes), and a short is 16 (2 bytes). As stated before, an int is also 32 bits. A bool could conceivably be 1 bit, but for the sake of reasons we can''t go into here (memory pipeline efficiency), it''s more often 1 byte or 4 bytes (seems like a waste of space? Don''t worry about it). The reason behind the different sizes of ints and floats is that memory usage used to be a concern. Now, more often, different sizes are used for clarity. Here''s a brief list of what a programmer thinks when they see a variable declared as a particular type:
short - "Hm, gonna be between -32000 and 32000, probably to indicate that this value won''t be too large at any point" - this might be an index into a string, which will rarely be more than 32000 bytes long.
long - "Could be a big number, probably indicates nothing special" - longs and ints are used interchangeably these days. They can indicate anything from the need to store a very large integer to sloppy programming. In other words, they''re a catch-all.
float - "Standard decimal number"
double - "Really big decimal number" - you''ll see floats more than doubles in game programming, and vice versa in academia

Now, signedness. This refers to whether a variable is signed or unsigned, which simply means that it can or cannot store negative values, respectively. Why?
1) For clarity: often, coders use unsigned variables to indicate that the value of the variable really should never be negative, like an array index or a number of objects
2) For the extra space. By declaring a variable as signed, you shift its capacity completely into the positive domain, giving you an extra bit (literally) of capacity. For example, both a signed int and unsigned int are 32 bits, but a signed int, because it uses one bit to store whether the number is positive or negative, can only store between -2.2 bil and 2.2 bil, whereas an unsigned integer can store between 0 and 4.28 bil.

quote:
Then I don''t understand "declaring variables"
ex: unsigned short NumberOfSons;
signed int MyAccountBalance;

Declaring a variable is just telling the compiler that you''ll be using a particular indentifier to store something. You''re probably either overcomplicating it in your mind, or not thinking logically about how programming works. Both are fine; they just take time to break.
quote:

Initialization of variables(dont get those)

Initializing a variable is giving it an initial value. This matters because if you don''t initialize a variable, it contains meaningless data. For example:
int Foo;
Foo now contains a number. What number? I have no idea, because it''s just whatever was in memory where the variable was placed.
int Bar = 4;
Bar equals four, like a good variable that''s in my complete control.
This issue becomes much more important with pointers, but save that for another day.
quote:

Then the rest just loses me...It might be because
I am bad at math. I never understand it until
after the test....kind of sucks...

Take it slow. This is hard shit.
quote:

Then the first part of operators looks easy, like:
+ / - * and then doing stuff like:
a++=b.

That statement is impossible. This indicates that you''re trying to view the problem as a whole, which you really shouldn''t do. You''ll learn how to split things up mentally as you go, then evaluate them in much the same way computers do. A computer can only do one thing (an add, an increment, a multiply, a temporary variable creation, whatever) at a time, so learn about order of operations, and learn to think linearly and logically on a small scale.
quote:

I don''t understand other simple things like void main()
and int main() and return 0 looses me too...

It''s all just nomenclature. Don''t be overwhelmed by stuff that doesn''t directly apply to the input and output of the system at this point.
quote:

Oh, and when I took that gametutorial.com thing for the text game,
it seemed like they made a lot of their own stuff up like:
strRoomNorth, STILL_PLAYING, void DisplayRoom,
GetRoomInfo...ect. How do you do stuff like that?

That''s the coolest part of programming: taking this relatively simple set of rules, and building with them to create something complex and unique. What they''re doing there is just making functions and variables that define how the game code works. Once you realize how closely "what you type in" and "what happens" relate, programming becomes a matter of becoming a better problem solver, and learning the tools that the language offers to make that job easier. Until you reach that point, it''s crucial that you dick around with code and see what effect tiny changes to the code have on the program''s behavior. Shortly, you''ll get the hang of how this programming thing works.

I hope I haven''t been too ambitious in replying to all this. Hope it''s of some use. Feel free to email me or AIM@zealouselixir if you have more questions.

Peace,
ZE.

//email me.//zealouselixir software.//msdn.//n00biez.//

##### Share on other sites
Ronin Magus    142
Well, I''ve been programming since I was 11 (about 8 years now..) but I reallllyy learned how to program when I took AP Computer Science classes in high school. Back then, they taught C++, but I believe they have moved to Java now (they were talking about that my senior year.)

I think that the endeavor should be to learn to "program," not to learn to a language. There are certain theories that must be understood. A person who can do something with C/C++ (or any other language) may not be a real programmer .. just like a guy who understands the theories of computer science may not know C/C++. But it is the latter that makes you a programmer.

daveandrews.org, soon to be home to a GAPI Sprite Engine.

##### Share on other sites
vaneger    100
well ok its like this:
#include<iostream.h> /*This includes input and outputfunctions into your program*/void main() // this is just the Main part of a program{/*when a computer runs the program it calls the function named Main()and executes the code inside of it*/      /*data types are simple thingsfor example say you have a bank accountyou need a name, amount of money in the account,intrest ratesand probably loads of other information. The point here thoughis that you need differnt kinds of information, thus differntdata types. integers and longs hold differnt amounts of data,if you know you wont need more than say 30,000 \$ in a givenbank account you could use an integer, but if you need more moneyin the account you need a data type that can hold higher numbers.names and things like are Char data types, and have values from 0 - 255 that equate to letters or symbols when displayed.unless you intend on having names like 1234243 you are going toneed differnt data types :)*//*to declare variables of differnt types you use char,int,float,long,etc,etc.here we declare 3 integers and do pathagorean''s theorm*/      int a = 5;      int b = 3;       int cSQRD = (a*a) + (b*b);/*now we just output the CSQRD variable*/      cout<<cSQRD<<endl; }

it really easy it is all about catergorizing what kind of information you have and what kind of data type represents it the best.

##### Share on other sites
Fruny    1658

* There is no standard C++ header called ''iostream.h''.
* main() returns int, not void.
* There is no cout object, but an std::cout.

[ Start Here ! | How To Ask Smart Questions | Recommended C++ Books | C++ FAQ Lite | Function Ptrs | CppTips Archive ]
[ Header Files | File Format Docs | LNK2001 | C++ STL Doc | STLPort | Free C++ IDE | Boost C++ Lib | MSVC6 Lib Fixes ]