A few questions about C++

Discussion in 'General Gaming Discussion' started by NINTENDO DS, Oct 26, 2008.


    NINTENDO DS GBAtemp Regular

    Jun 10, 2008
    United States
    in a mall
    It's the first time i use the program, and I am using C++ for dummies.

    There is a bunch of complicated stuff.

    What do these frameworks mean, and when do I use each one?
    Warning: Spoilers inside!

    Also any advice about anything would be nice.
  2. Normmatt

    Normmatt Former AKAIO Programmer

    Dec 14, 2004
    New Zealand
    Whats complicated about that code? we need more information.
  3. Jiggah

    Jiggah GBAtemp Maniac

    Nov 9, 2002
    United States
    As the poster above said, what's complicated?

    #include - a way of importing header files, classes, and libraries outside of the main program, which contains functions that you want to use in your main program.
    cstdio and cstlib - allows you to use read, write, and manipulate files i.e. text files.
    iostream - allows you to output and input data. you can't use cout or cin if this is not included. basically, you can't print to the console if you don't include this.

    using namespace std; - tells the program where in iostream to look for calls.

    int main() - this always needs to be in the program, this is the main body of the program and is usually empty or is void i.e. void main() or int main(void)
    int nNumberofArgs, char* pszArgs[] - these are arguments for the main function. One is initialized as an integer and one as a character array.

    system("pause") - needed for vc++ 2008, other compilers may not needed it. It tells the console to stop before exiting the program.

    You also need to return 0, since it's int main() and not a void main(), and close the main function, which you're missing from that example.

    A very basic console program would look like this.

    using namespace std;

    int main()

  4. 13375p34k3r

    13375p34k3r GBAtemp Regular

    Sep 25, 2007
    Markham, Ontario
    Honestly I would recommend starting to learn programming with Python. It is much more user friendly because it is a high-level interpreted language. That resembles the English language in many ways. Also I wouldn't recommend Visual C++, CODE::Blocks is a much better piece of software that is Open Source.
  5. Psyfira

    Psyfira Credit: 0ml. Insert tea to continue

    Dec 31, 2003
    For those "include" statements, they let you use code from other files (called header files). You can write your own header files later on, but C++ provides some for you (for common tasks like reading files, keyboard presses, etc) so you don't have to write it out yourself and that's what is being used here (you have to state which ones you want to use). There's a guide to the provided header files and what they all do here:
    C++ Library Reference
    Might not make much sense when you're first starting out but stick with it [​IMG]

    Also, you might find if you're right at the start of the book it explains them later on. Yes I know it's annoying, I had a lecturer who used to do that (but a lot worse). If you are right at the very start of the book, it should at least be explaining the "main" method now.
  6. lookout

    lookout GBAtemp Board Room

    Aug 16, 2006
    United Kingdom
    You're missing a lot of semi colons....

    something like this?:

    using namespace std;

    int main(int nNumberofArgs, char* pszArgs[])
  7. Joe88

    Joe88 [λ]

    Jan 6, 2008
    United States
    int main should be left blank like since your not really doing anything with it (I dont know how the new c++ express works, im just basing this off a VS 6.0)
    int main()

  8. UltraMagnus

    UltraMagnus hic sunt dracones

    Aug 2, 2007
    nothing seems complicated there to me.

    honestly, you should start with C first, then go onto C++ if you want

    or learn ASM first is probably the best thing to do.
  9. BigX

    BigX GBAtemp Regular

    Aug 29, 2007
    over there
    1. OP should think about what he wants to do and why to learn programming
    2. C++ is just one mean of software development.
    3. If the posted sample is already to complicated, the OP missed some things about software development.

    I studied 8 semester of computer science and work for four years after that as software developer. There are still some techniques with C++ not clear to me.
    Many people use C/C++ because it is so powerfull. But this power comes with some problems.
    If you are able to do anything, the downside is, you HAVE to do anything.
    Wherein Java or Python you have "simple" methods for input and output and string operations, performing the same task with C/C++ you'll have to implement (or reuse) some basic stuff.
    You should also learn some things about OO (that's object orientation).

    Basically explaining the sample code to you would not give you any insight.