Learning C++

QuaunautQuaunaut The longest seven days in history... Join Date: 2003-03-21 Member: 14759Members, Constellation, Reinforced - Shadow
<div class="IPBDescription">In the "Visual C++ Toolkit 2003" Environ</div> Anyone have any tutorials for this? I'm trying everything I can to learn, and I'd love if I can get some of it. <3
«1

Comments

  • DOOManiacDOOManiac Worst. Critic. Ever. Join Date: 2002-04-17 Member: 462Members, NS1 Playtester
    Best advice I can give you is if you want to learn C++, forget about Windows programming. Its hard enough to really learn the language, it'll only confuse and distract you if you pick up one of those "Learn Visual C++ in 30 _____" books.

    Just go to the book store and get a good old fashioned paper bound book.
  • QuaunautQuaunaut The longest seven days in history... Join Date: 2003-03-21 Member: 14759Members, Constellation, Reinforced - Shadow
    <!--QuoteBegin-DOOManiac+Jun 14 2004, 04:47 PM--></div><table border='0' align='center' width='95%' cellpadding='3' cellspacing='1'><tr><td><b>QUOTE</b> (DOOManiac @ Jun 14 2004, 04:47 PM)</td></tr><tr><td id='QUOTE'><!--QuoteEBegin--> Best advice I can give you is if you want to learn C++, forget about Windows programming. Its hard enough to really learn the language, it'll only confuse and distract you if you pick up one of those "Learn Visual C++ in 30 _____" books.

    Just go to the book store and get a good old fashioned paper bound book. <!--QuoteEnd--> </td></tr></table><div class='postcolor'> <!--QuoteEEnd-->
    I have, but its built for their compiler, and is DOS based. I wanna do Windows based, being Dos is dead and all...
  • DOOManiacDOOManiac Worst. Critic. Ever. Join Date: 2002-04-17 Member: 462Members, NS1 Playtester
    Download borland's free command line compiler or gcc/gpp/whatever they call it on windows.

    And you're gonna be writing console apps to begin with. You can't just start off w/ windows crap if you wanna learn it right.
  • QuaunautQuaunaut The longest seven days in history... Join Date: 2003-03-21 Member: 14759Members, Constellation, Reinforced - Shadow
    Wait, as in stuff for XBox and PS2 and the like?

    TBH, I wanted to cut my teeth on HL mods, being its so-called the best place to start out.
  • SkySky Join Date: 2004-04-23 Member: 28131Members
    lol
    no, not that kind of console.
    i just took a half year of the most crap-**** C++ course in school, so I'm not one to go to for advice. but a console application is like a program that runs in something that looks like a DOS window. I think.
  • SwiftspearSwiftspear Custim tital Join Date: 2003-10-29 Member: 22097Members
    The console Doom is refering too is the console that runs DOS within Windows. Starting with console apps is a must, it creates the simple basis for which all other C++ is programmed. I doubt very much that it is possible to know how C++ works without knowing how to make a quality console app program, It would be like learning powers before multiplication.
  • QuaunautQuaunaut The longest seven days in history... Join Date: 2003-03-21 Member: 14759Members, Constellation, Reinforced - Shadow
    <!--QuoteBegin-5kyh16h91+Jun 14 2004, 05:38 PM--></div><table border='0' align='center' width='95%' cellpadding='3' cellspacing='1'><tr><td><b>QUOTE</b> (5kyh16h91 @ Jun 14 2004, 05:38 PM)</td></tr><tr><td id='QUOTE'><!--QuoteEBegin--> lol
    no, not that kind of console.
    i just took a half year of the most crap-**** C++ course in school, so I'm not one to go to for advice. but a console application is like a program that runs in something that looks like a DOS window. I think. <!--QuoteEnd--> </td></tr></table><div class='postcolor'> <!--QuoteEEnd-->
    Thats what the Visual C++ thing is. Its a comiler thing, but the setup is much like the console. Or should I use the console itself?

    I'm not a total newb to this, but I'm close, so please explain everything.
  • SwiftspearSwiftspear Custim tital Join Date: 2003-10-29 Member: 22097Members
    One of the options for programs you can write should be a Win32ConsoleApp. Essentially, this is a dos text program running in a windows console (the same console that runs if you put "cmd" into Run... under the start menu in windows).

    This environment serves as the training ground for all up and coming programers of C++ because it is the easyest place to get a good grounded understanding of how C++ as a code language works. Type "hello world tutorial C++" into google (or look for a hello world tutorial for whatever compiler you are using) and do whatever the tutorial says. If all goes according to plan (ie. you don't have any syntax errors, which means input mistakes like 'cout>>"hello world";' instead of 'cout<<"hello world";') you should have writen your first program. After that, try to find good indepth tutorial or "learn in 30 days" book, you should be able to learn enough syntax and funtions stuff for other stuff like object oriented programing and what not to make sence.

    It will be a while before you are hot stuff in Halflife, though I imagine that with basic C++ knowlage and the aid of a good tutorial it shouldn't be hard to figure out what is going on.
  • juicejuice Join Date: 2003-01-28 Member: 12886Members, Constellation
    edited June 2004
    As in learning C++ to make games?

    If you're just starting out ("console as in xbox?" no...hehe, you even need architecture knowledge for that...oh yeah and that dev license thing), you'll be in console appland for some time anyway, as doom said. Which means your programs "look like they're in DOS." You know? Crappy, text-only, not windows-pretty... console. Like the Half-Life Console, but in Windows. Yes, it may be ugly, and of course you want to make Windows apps, BUT you have to program like this to start out because it is a prerequisite for everything else.

    <!--QuoteBegin--></div><table border='0' align='center' width='95%' cellpadding='3' cellspacing='1'><tr><td><b>QUOTE</b> </td></tr><tr><td id='QUOTE'><!--QuoteEBegin-->I have, but its built for their compiler, and is DOS based.<!--QuoteEnd--></td></tr></table><div class='postcolor'><!--QuoteEEnd-->

    Until you learn the language, neither your environment/compiler nor platform are of too much concern. All you have to do is have basic knowledge of how to compile the single .cpp files that you'll be writing, and you can start learning c++. Maybe check your complier's documentation if that's giving you problems...

    Get a solid book on the language, I recommend C++ Primer Plus. Go through those 1000 pages, then you can try your hand at, say, modifying someone's open source HL bot. You don't need windows programming to start hacking away at HL. It can be overwhelming because of its size, but if you want to cut your teeth on it, go for it. If you want to make your own engine, or even a simple app, in Windows, this requires a whole extra set of knowledge. I'd recommend LaMothe's "Tricks of the Windows Game Programming Gurus". It covers windows apps + directx + lots of game-related stuff. Which is fun. It's not really a tricks and tips book, it's more like a textbook for making a game. But that's only 2d. A 3d engine requires even more... so... yeah get back to me after those first 2000 pages are done and you've hacked hl a little. And know too well what a console application is. <!--emo&:D--><img src='http://www.unknownworlds.com/forums/html//emoticons/biggrin.gif' border='0' style='vertical-align:middle' alt='biggrin.gif' /><!--endemo-->

    Edit: swiftspear stole my thunder.
  • QuaunautQuaunaut The longest seven days in history... Join Date: 2003-03-21 Member: 14759Members, Constellation, Reinforced - Shadow
    Swiftspear: So far I have made about 3 programs, surrounding...being a calculater...without anything fancy(i.e. square root, squaring...anything besides the 4 basics), so I'm not a total nubbeh, as well as a program to convert Fahrenheit into Celsius.

    I actually had a few questions to start with:

    What the hell is <stdio.h> or <lostream.h>? It has at the start of most the programs out of the one book I have(C++ for Dummies, 4th edition where they assume you know nothing)- here's what it looks like in there if it helps:

    <!--c1--></div><table border='0' align='center' width='95%' cellpadding='3' cellspacing='1'><tr><td><b>CODE</b> </td></tr><tr><td id='CODE'><!--ec1-->#include <stdio.h>
    #include <iostream.h>

    int main(int nNumberofArgs, char* pszArgs[])<!--c2--></td></tr></table><div class='postcolor'><!--ec2-->

    Thats the start of it, with the stuff of how to do it(which I can understand pretty well, as will as the cin cout stuff).
  • [WHO]Them[WHO]Them You can call me Dave Join Date: 2002-12-11 Member: 10593Members, Constellation
    edited June 2004
    iostream.h
    this one provides all those c++ input and output streams.
    e.g. cout << "hello world";

    stdio.h
    this provides the older style c input and output (which is far superior in my opinion)
    e.g. printf("hello world");


    You need these to make your life easier. C/C++ on it's own is amazingly useless for anything besides number crunching and data movement. These "headers" have a plethora of c/c++ code in them that has been built up over months (years maybe?) of time to abstract the data movement required to achieve input and output so you don't have to worry about it.

    Nine tenths of the point of learning C++ is learning to abstract, and then abstract that, and abstract that.


    EDIT: better explanation given.
  • QuaunautQuaunaut The longest seven days in history... Join Date: 2003-03-21 Member: 14759Members, Constellation, Reinforced - Shadow
    Where can I get a compiler that is easy to understand? I've written code, saved it as "myprog.cpp", and now am just wondering how in the hell to compile.

    Anyone know how to compile it in the Microsoft Visual C++ 2003 Toolkit Command Prompt? Or any other compilers that are easier/better to use?
  • [WHO]Them[WHO]Them You can call me Dave Join Date: 2002-12-11 Member: 10593Members, Constellation
    Just read the help files or a manual. I seriously think this is a problem you need to tackle yourself.

    Just keep in mind that most of the time your code needs to be compiled into object files, and those object files need to be linked using a linker.

    Linkers are always packaged together with the compilers, and some compilers will do both steps for you at once with the proper commandline arguments.
  • [WHO]Them[WHO]Them You can call me Dave Join Date: 2002-12-11 Member: 10593Members, Constellation
    If all else fails, research the concept of a makefile.
  • SkySky Join Date: 2004-04-23 Member: 28131Members
    <!--QuoteBegin-[WHO]Them+Jun 14 2004, 09:29 PM--></div><table border='0' align='center' width='95%' cellpadding='3' cellspacing='1'><tr><td><b>QUOTE</b> ([WHO]Them @ Jun 14 2004, 09:29 PM)</td></tr><tr><td id='QUOTE'><!--QuoteEBegin--> Just keep in mind that most of the time your code needs to be compiled into object files, and those object files need to be linked using a linker.
    <!--QuoteEnd--> </td></tr></table><div class='postcolor'> <!--QuoteEEnd-->
    How's about he compile the one .cpp file he has now before he tries to #include object files. I may have had a crappy book, but objects were in like chapter 14. He hasn't even gotten one program.
  • QuaunautQuaunaut The longest seven days in history... Join Date: 2003-03-21 Member: 14759Members, Constellation, Reinforced - Shadow
    Okay, I found a good compiler, that even helps me learn- Dev C++(thanks Otto!)

    This program I got from the dummies book, but whenever I run it, it runs, asks the first question, I enter it, and then it crashes. Explain?

    <!--c1--></div><table border='0' align='center' width='95%' cellpadding='3' cellspacing='1'><tr><td><b>CODE</b> </td></tr><tr><td id='CODE'><!--ec1-->#include <stdio.h>
    #include <iostream.h>

    int main(int nNumberofArgs, char* pszArgs[])
    {
       // enter the temperature in Celsius
       int celsius;
       cout << "Enter the temperature in Celsius:";
       cin >> celsius;
       
       // calculate conversion factor for Celsius
       // to Fahrenheit
       int factor;
       factor = 212 - 32;
       
       // use conversion factor to convert Celsius
       // into Fahrenheit values
       int fahrenheit;
       fahrenheit = factor * celsius/100 + 32;
       
       // output the results
       cout << "Fahrenheit value is:";
       cout <<  fahrenheit;
       
       return 0;
    }    
    <!--c2--></td></tr></table><div class='postcolor'><!--ec2-->
  • SkySky Join Date: 2004-04-23 Member: 28131Members
    edited June 2004
    don't you have to put "using namespace std;" after the includes?

    also, I've never seen this method for converting F to C. I always use the F = 9/5 * C + 32 or somesuch.
  • SwiftspearSwiftspear Custim tital Join Date: 2003-10-29 Member: 22097Members
    this might just be my C++ nubness, but I don't think you need those input data types in your main function. I'm pretty sure it should read "int main (void)".

    Someone who knows more about C++ correct me, I have never seen inputs in the main function in consoles apps ever before.

    <!--QuoteBegin--></div><table border='0' align='center' width='95%' cellpadding='3' cellspacing='1'><tr><td><b>QUOTE</b> </td></tr><tr><td id='QUOTE'><!--QuoteEBegin-->
    don't you have to put "using namespace std;" after the includes?
    <!--QuoteEnd--></td></tr></table><div class='postcolor'><!--QuoteEEnd-->
    except that he isn't using namespace... note the .h after the iostream.

    acctually Quauna, you aren't using <stdio.h>, you might as well disinclude it.

    If all else fails, pull the .h's of your #include's and put "using namespace std;" under them.
  • QuaunautQuaunaut The longest seven days in history... Join Date: 2003-03-21 Member: 14759Members, Constellation, Reinforced - Shadow
    <!--QuoteBegin-Swiftspear+Jun 14 2004, 07:52 PM--></div><table border='0' align='center' width='95%' cellpadding='3' cellspacing='1'><tr><td><b>QUOTE</b> (Swiftspear @ Jun 14 2004, 07:52 PM)</td></tr><tr><td id='QUOTE'><!--QuoteEBegin--> this might just be my C++ nubness, but I don't think you need those input data types in your main function. I'm pretty sure it should read "int main (void)".

    Someone who knows more about C++ correct me, I have never seen inputs in the main function in consoles apps ever before.

    <!--QuoteBegin--></div><table border='0' align='center' width='95%' cellpadding='3' cellspacing='1'><tr><td><b>QUOTE</b> </td></tr><tr><td id='QUOTE'><!--QuoteEBegin-->
    don't you have to put "using namespace std;" after the includes?
    <!--QuoteEnd--></td></tr></table><div class='postcolor'><!--QuoteEEnd-->
    except that he isn't using namespace... note the .h after the iostream.

    acctually Quauna, you aren't using <stdio.h>, you might as well disinclude it.

    If all else fails, pull the .h's of your #include's and put "using namespace std;" under them. <!--QuoteEnd--> </td></tr></table><div class='postcolor'> <!--QuoteEEnd-->
    I did the "If all else fails", and while it compiled fine, it didn't fix my problem of the sudden crash without telling me my result.
  • CabooseCaboose title = name(self, handle) Join Date: 2003-02-15 Member: 13597Members, Constellation
    What it sounds like... to me... is that you are not reading the book... I have that book... 4th edition, same exact book... If you read it... you might know what iostream.h is...

    You can not expect to learn C++ in a matter of days. It's it's own language, just as complex as any that man speaks...

    The GNU compiler inclused with that book is one of the best compilers you will find too...

    Also, it shouldm't crash. My guess is that you are having the compiler run the program...

    Try running it from the cmd prompt. What's probly happening is that it gives you an answer and since the program is over, it exits because to the computer, it has done it's job.
  • SwiftspearSwiftspear Custim tital Join Date: 2003-10-29 Member: 22097Members
    edited June 2004
    Sounds like a logic error, the only thing in your code that looks to me like a logic error, is that you tell the main function that you are giving it data types it never recives. Try "int main (void)" as the header for the main function.

    [edit] caboose is right, your problem is not that your program is crashing, its that finished dos exe's run till compleation and then close. Compile your program as a test compile using the run function, it should ask you to press the enter key when the program is over rather than just closing.

    [edit2] you could also hack your own end program into the program by putting another useless cin statement just before return 0,

    <!--c1--></div><table border='0' align='center' width='95%' cellpadding='3' cellspacing='1'><tr><td><b>CODE</b> </td></tr><tr><td id='CODE'><!--ec1-->
    int useless =0;
    cin >> useless;
    return 0;
    <!--c2--></td></tr></table><div class='postcolor'><!--ec2-->
  • SkySky Join Date: 2004-04-23 Member: 28131Members
    derr...wow. My intelligence goes straight down the crapper at night. Not that I have much to begin with...
    I honestly can't remember clearly right now, but if this were me writing this program it'd go something like:

    <!--c1--></div><table border='0' align='center' width='95%' cellpadding='3' cellspacing='1'><tr><td><b>CODE</b> </td></tr><tr><td id='CODE'><!--ec1-->
    #include <iostream>
    using namespace std;

    int main()
    {
      int celsius = 0;
      int factor = 180;
      int fahrenheit  = 0;

      cout << "Enter the temperature in Celsius:";
      cin >> celsius;
       
      fahrenheit = factor * celsius / 100 + 32;
     
      cout << "Fahrenheit value is: " <<  fahrenheit << endl;
     
      return 0;
    }    

    <!--c2--></td></tr></table><div class='postcolor'><!--ec2-->

    damn you finals!
    *asleep*
  • CabooseCaboose title = name(self, handle) Join Date: 2003-02-15 Member: 13597Members, Constellation
    edited June 2004
    No errors. I went and d/l'd Dev C++ 5 and copy pasted it. Did compile and run. It asked me to enter celcius. I hit 3 then enter

    program exits

    Then I run it from the command prompt. wow, it exits, but the result stays there... lookey here...
  • QuaunautQuaunaut The longest seven days in history... Join Date: 2003-03-21 Member: 14759Members, Constellation, Reinforced - Shadow
    edited June 2004
    <!--QuoteBegin-Caboose+Jun 14 2004, 08:00 PM--></div><table border='0' align='center' width='95%' cellpadding='3' cellspacing='1'><tr><td><b>QUOTE</b> (Caboose @ Jun 14 2004, 08:00 PM)</td></tr><tr><td id='QUOTE'><!--QuoteEBegin--> What it sounds like... to me... is that you are not reading the book... I have that book... 4th edition, same exact book... If you read it... you might know what iostream.h is...

    You can not expect to learn C++ in a matter of days. It's it's own language, just as complex as any that man speaks...

    The GNU compiler inclused with that book is one of the best compilers you will find too...

    Also, it shouldm't crash. My guess is that you are having the compiler run the program...

    Try running it from the cmd prompt. What's probly happening is that it gives you an answer and since the program is over, it exits because to the computer, it has done it's job. <!--QuoteEnd--></td></tr></table><div class='postcolor'><!--QuoteEEnd-->
    I'd love to see the page with that. Unless it explains it after chapter 6, I have not read it anywhere.

    I understand it won't be a couple of days. I don't care HOW long it takes, I'm not expecting so. I'm just wondering about it on a simple program. I'm not some kind of idiot here. This book has so many errors- with its OWN COMPILER - that its almost inexcusable. Every program but 1 of them I've done so far(the 2nd) has not worked without ME PERSONALLY looking over their code and tweaking it. I know enough of it to do that at least.

    As to the rest: None of those solutions have worked to show me anything at all, as well as the code 5kyh16h91 gave. I think it may be a problem with my compiler trying to run it- but it should do it fine, being all it does is start its own command prompt and do all the legwork for me.

    *edit* After doing it in the original command prompt the way you have, it works. Though I don't understand why it wouldn't from the compiler- can you explain that(no sarcasm there, honest wondering). Thanks for the help though.
  • CabooseCaboose title = name(self, handle) Join Date: 2003-02-15 Member: 13597Members, Constellation
    edited June 2004
    Like I said, the program worked, it just ended too fast for you to see the result.

    :edit for clarification:
    The reason is, it's done it's job and without any instructions to wait for permission to exit, it exits.
  • QuaunautQuaunaut The longest seven days in history... Join Date: 2003-03-21 Member: 14759Members, Constellation, Reinforced - Shadow
    <!--QuoteBegin-Caboose+Jun 14 2004, 08:14 PM--></div><table border='0' align='center' width='95%' cellpadding='3' cellspacing='1'><tr><td><b>QUOTE</b> (Caboose @ Jun 14 2004, 08:14 PM)</td></tr><tr><td id='QUOTE'><!--QuoteEBegin--> Like I said, the program worked, it just ended too fast for you to see the result. <!--QuoteEnd--> </td></tr></table><div class='postcolor'> <!--QuoteEEnd-->
    Hmm...time to downgrade to that Pentium 4 .000000000000000001ghz. <!--emo&:D--><img src='http://www.unknownworlds.com/forums/html//emoticons/biggrin.gif' border='0' style='vertical-align:middle' alt='biggrin.gif' /><!--endemo-->
  • SwiftspearSwiftspear Custim tital Join Date: 2003-10-29 Member: 22097Members
    edited June 2004
    <!--QuoteBegin-Swiftspear+Jun 14 2004, 10:01 PM--></div><table border='0' align='center' width='95%' cellpadding='3' cellspacing='1'><tr><td><b>QUOTE</b> (Swiftspear @ Jun 14 2004, 10:01 PM)</td></tr><tr><td id='QUOTE'><!--QuoteEBegin--> <!--c1--></div><table border='0' align='center' width='95%' cellpadding='3' cellspacing='1'><tr><td><b>CODE</b> </td></tr><tr><td id='CODE'><!--ec1-->
    int useless =0;
    cin >> useless;
    return 0;
    <!--c2--></td></tr></table><div class='postcolor'><!--ec2--> <!--QuoteEnd--></td></tr></table><div class='postcolor'><!--QuoteEEnd-->
    to qoute my edit. Basicly your problem is that basic exe's close as soon as they finished, so your answer is processing, it is just processing printing and closeing so fast you don't get to see it. Hack a "press enter to end program" system together using the above code where it appears in conjunction to "return 0" in my code (the first two lines go right above the "return 0" in your program)

    [edit] most people wouldn't need to worry about this solution because microsoft visual C++ automatically asks for you to press enter to end the program, and most people just happen to use that particular software.
  • QuaunautQuaunaut The longest seven days in history... Join Date: 2003-03-21 Member: 14759Members, Constellation, Reinforced - Shadow
    I thank you all a lot, I really appreciate all of this. I just hope you continue to be this receptive about the stuff, as I am quite liable to come here for answers.
  • SwiftspearSwiftspear Custim tital Join Date: 2003-10-29 Member: 22097Members
    No problem, I like debugging code, expecially without a debugger <!--emo&:p--><img src='http://www.unknownworlds.com/forums/html//emoticons/tounge.gif' border='0' style='vertical-align:middle' alt='tounge.gif' /><!--endemo-->
  • SoulSkorpionSoulSkorpion Join Date: 2002-04-12 Member: 423Members
    Some general advice on learning C++:

    "... for dummies" or "in 20 days" books are ok for a basic introduction, but you <i>need</i> better than that. There are two major problem with these books - firstly, they seldom last you more than 20 days. The other problem is more severe: they often teach you bad habits. What's a bad habit? Something that's non-standard, or something that's doing things the C way when there's a better and more painless version in the C++ way.

    I highly encourage you to stick to standard C++ whenever possible, and to try to favour C++ constructs over C. It's not just being pedantic. In the long run, it'll make your life easier. I don't mean for you to constantly worry about whether your code is standard or not, but as you learn what is standard and what isn't, prefer the standard versions.

    The other thing is that C++ is a <i>very</i> large language. There are a lot of keywords, and often keywords mean different things in different contexts. That's because C++ was designed to support several different, seperate programming concepts, and because it supports (nearly all of) C. Try not to be daunted by this, just learn the bits you need. Don't bother about templates, STL, classes, operator overloading, object orientation and all that mess until you're familiar and comfortable with the language itself. For the same reason, while Windows programming is a good thing to know, until you're comfortable and competant with the language itself, it's not going to help you much.

    Anyways, good luck and have fun <!--emo&:)--><img src='http://www.unknownworlds.com/forums/html//emoticons/smile.gif' border='0' style='vertical-align:middle' alt='smile.gif' /><!--endemo-->. Oh, and if there's something that seems especially painful about the language, feel free to post about it - it might be that that's a Cism, and that there's a more painless way to do it.
Sign In or Register to comment.