Learning C++

omlette

Newbie
Joined
Jul 6, 2003
Messages
345
Reaction score
0
Hey. I'm really interested in being able to make minor modifications to HL2, if I can ever get it to compile. So, I need to learn C++... problem is, I have no idea where to start. And even if I did, C++ isn't unified as each compiler does things its own way, and thus anything I learn may be obsolete or just plain not right.

So my question is, what is the best way to go about learning C++? Thanks!
 
yes, compilers do work in different ways, but the right compiler in this case is most definitely MS VisualStudio .net. If you just want to start by learning C++, get MS visual c++ 6.0 or greater. Dealing with the most popular compiler makes things easy when learning.

As for books, I've recently read "c++ from the Ground up" by Herbert Schildt. Schildt writes very clearly. The other one to read is "C++ Primer Plus" 4th ed. These are the best books for learning c++. Learning 'the language' and learning 'to program' are very different things, you'll learn. One takes you less than a month, the other years. But it's where you have to start. And if all you want to do is read code and change a few values, you should get on OK.
 
Well, I can't say fore sure. I'm a programming nubie, for the most part.

Taking a class would probably be a good option. It really helps to hvae someone who you can ask about a problem or question when it comes up. You can find a number of online tutorials and such, just get a compiler and try some of them out. If you understand basic programming concepts (for example: variables, declarations, functions, loops, objects, pointers, arrays, etc...) then you should be able to go through them without too much trouble. The syntax can be kind of confusing at times, but some practice should get you past that.

www.cplusplus.com (Edit: Under documents, 'the C++ language tutorial') has some good information about the basic modis operandi of C++, how the basic structures and operators work. Read through it and try to understand...

But all the book reading in the world doesn't replace some practical experaince. Try making some simple programs with the things you learn. You could try getting the SDK and making very small changes to effect the game... getting a hang of HL2 itself.. I dunno.

Anyway, IMO the compiler isn't a big issue. All languages go through some amount of change. Of course if you just want to get something simple to work, I understand wanting to have a compiler that 'just works'. A full featured IDE might be good, they can help deal with the details, and might provide better feedback for debugging etc. I.E. -- Borland or VS .NET maybe, if you can get them.

Again, I'm a nUb, so I can't tell you what process made me a great coder, just an idea where I started. I still suck though. My $0.02

GL :)
 
Spend 100 bucks and order the C++ bundle from 3dbuzz... like 12 hours of tutorials and shows you how to make a game for your GameBoy Advance!!! Of course it will be with ASCII art, but in the last two VTMs you port it to a 1337 graphics engine that uses sprites, and also shows you how to make a level editor...

Don't believe me?

Here is the intro to Issue3.. Shows it running on the GameBoy Advance.

http://sv3.3dbuzz.com/vbforum/showthread.php?s=&threadid=57097


Here is the intro to Issue5 which shows it running on Windows with fancy graphics, and shows the level editor

http://sv3.3dbuzz.com/vbforum/showthread.php?s=&threadid=89840


Want to order?

http://sv3.3dbuzz.com/xcart/custome...&XCARTSESSID=1dd444ff194528c2fbc7b4a870df8dc1

You have to the 10th, or else it will be 250 bucks! for all 5 issues.
 
You have to buy at least one decent book. It's just much easier to read an actual book and looks things up in it.

Make sure you don't just learn C and then C++ otherwise you'll get stuck writing your programs using just functions as opposed to classes which is the whole point of OO programming.
 
The most important thing is practice .. practice and pratice!
You won't really begin to understand programming untill you've practiced alot!
if you are a beginner, you will probably look at some chunk of code then wonder how the hell is that supposed to swing the crowbar!
but as you advance, digesting code will become easier.

I can't claim myself to be anything above "n00b", but I think I can now sorta understand the SDK, atleast I can do it far better than I was two years ago (with hl1 SDK).
 
Well to go further, practice is good, but EXPERIMENT!!!

Don't just do the same program... figure out what you can/can't do, think of something crazy and try it out... in my short few weeks of learning I've had so many compile issues, but I've learned so many things from them (such as in a single function you can't have different variable types (float, int, double) it must be unified... afaik)

For example... build a coke machine!!!!!!!!!!!!

Code:
#include <iostream>

using namespace std;

main()
{
      int money = 10;
      int user = 1;
      
      switch(user)
      {
        case 1:
             money += 25;
             break;
        case 2:
             money += 10;
             break;
        default:
                cout << "Spit it out!" << endl;
         }
      
      if (money > 35)
      {
         cout << "You have " << (money - 35) << " cents in change!" << endl;
      }
      
      if (money == 35)
      {
         cout << "You've got a Coke!" << endl;
      }
      else
      {
         cout << "Put " << (35 - money) << " more cents in!" << endl;
      }
      
cin.get();
return 0;
}
 
Iced_Eagle said:
(such as in a single function you can't have different variable types (float, int, double) it must be unified... afaik)


You got that wrong - you can have as many types as you want in a function.

I find that books are the best way to go. Tutorials are online, but books generally explain with larger details, and everything is in one little spot.
 
I'm keeping an eye on this thread, I'm going to have to start dabbling in coding too.
 
@nbk
I think he means functions can only have 1 return type, not sure.

@Iced_Eagle
You really should use a proper declaration of main (int main() or int main( int argc, char *argv[] ))
 
I'm readying Sams teach yourself C++ in 21 days. I made it through 14 chapters in a week and then life got busy again. I knew a little C beforehand which helped in the early stages. Anyway, the book is good and would recommend it to anyone just starting out.
 
I read Sams Teach Yourself C++ in 24 hours, didn't really like it all that much. If anyone wants to learn C first then C++ (not a bad idea), I highly recommend "Learning C". Also, something that I'm finding that many people don't know very well is the Win32 API. Any thoughts about learning that? I learned from theForger's tutorials.
 
Iced_Eagle said:
(such as in a single function you can't have different variable types (float, int, double) it must be unified... afaik)

That's crazy talk! So you don't think this is allowed:

Code:
void foo()
{
    int i;
    float j;

    ...
}

Course that's allowed!
 
Well then I screwed up my program... Time to go use that magic word, experiment again :)

It was probably the beta compiler I was using lol

Oh and that prog up there was really a joke... Don't take it seriously but I was just proving my point to practice/experiment.

Alright just tested out a simple math program, and copied it between the two compilers I was working on... indeed one didn't like the code and gave me errors, while the other was fine.... and the one that gave me errors is still beta soooo =\

BTW I'm still learning, just sharing what I'm learning too, so I do make tons of mistakes/bad habits in coding.

Well could you guys help me with this? I rushed on the code, so maybe mistakes.

Code:
#include <iostream>

using namespace std;

int main()
	{
	int x = 5;
	int y = 4;
	float total = 0;

	cout << "The answer to " << x << " / " << y << " is " << (total = (x / y)) << endl;
		
	}

Now it puts the data of x/y into total... x,y = int and total = float... now shouldn't it give me a float instead of an int output? or does when the data transfer over, it has to store it in the int format (4 bytes/bits whatever) and thus before it transfers that data to total, it already loses it? That's what I think... because as soon as I change one value (x or y) to a float, then it works...

Meh I love being a noob, but hey we all start somewhere :)



Oh and do please note I put "afaik" in there which means as far as I know so obviously I was proven wrong :)
 
Well, if x and y must both be ints, for whatever reason, you can achieve the desired result with a cast of one of the two:
Code:
#include <iostream>

using namespace std;

int main()
{
	int x = 5;
	int y = 4;
	float total = 0.0;

	cout << "The answer to " << x << " / " << y << " is "
	     << (total = ((float) x / y)) << endl;

	return 0;
}
Or just make one (or both) of x and y a float, as you said. The reason "total" stores an integer value is that (x / y) is handled in isolation, as an int divided by an int, which naturally rounds the answer out.

BTW someone mentioned Schildt; I've only ever heard terrible things about his books. It may be untrue, but he seems to have a reputation as being someone who doesn't follow standards, and gives bad or even erroneous examples in his texts.
 
Back
Top