A few questions about C++

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

Oct 26, 2008

A few questions about C++ by NINTENDO DS at 1:46 AM (1,392 Views / 0 Likes) 8 replies

  1. NINTENDO DS
    OP

    Member NINTENDO DS GBAtemp Regular

    Joined:
    Jun 10, 2008
    Messages:
    113
    Location:
    in a mall
    Country:
    United States
    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

    Member Normmatt Former AKAIO Programmer

    Joined:
    Dec 14, 2004
    Messages:
    2,135
    Country:
    New Zealand
    Whats complicated about that code? we need more information.
     
  3. Jiggah

    Member Jiggah GBAtemp Maniac

    Joined:
    Nov 9, 2002
    Messages:
    1,223
    Country:
    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.

    #include
    using namespace std;

    int main()
    {

    cout
     
  4. 13375p34k3r

    Member 13375p34k3r GBAtemp Regular

    Joined:
    Sep 25, 2007
    Messages:
    159
    Location:
    Markham, Ontario
    Country:
    Canada
    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

    Member Psyfira Credit: 0ml. Insert tea to continue

    Joined:
    Dec 31, 2003
    Messages:
    3,887
    Location:
    England
    Country:
    United Kingdom
    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

    Member lookout GBAtemp Board Room

    Joined:
    Aug 16, 2006
    Messages:
    1,619
    Location:
    United Kingdom
    Country:
    United Kingdom
    You're missing a lot of semi colons....




    something like this?:


    #include
    #include
    #include
    using namespace std;

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

    Member Joe88 [λ]

    Joined:
    Jan 6, 2008
    Messages:
    11,191
    Location:
    NYC
    Country:
    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

    Member UltraMagnus hic sunt dracones

    Joined:
    Aug 2, 2007
    Messages:
    1,967
    Location:
    Portsmouth
    Country:
    United Kingdom
    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

    Member BigX GBAtemp Regular

    Joined:
    Aug 29, 2007
    Messages:
    292
    Location:
    over there
    Country:
    Canada
    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.
     

Share This Page