How To Create A Console Application [C++] menu

Shout-Out

User Tag List

Results 1 to 4 of 4
  1. #1
    oblivion912's Avatar Banned
    Reputation
    9
    Join Date
    Feb 2009
    Posts
    63
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How To Create A Console Application [C++]


    Code:
    #include <cstdlib>
    You use this header for general operations and also because it defines multiple things, these include dynamic memory management, random number generation, communication with the environment, integer arthmetics, searching, sorting and converting.

    Code:
    #include <iostream>
    This is another header, execpt this one you use for when you want to use "cout" and "cin".

    Woot, we've finished the headers. Did I loose you? Well don't stop now were not even half way.

    Code:
    using namespace std;
    When you use this code in C++ its for everything, a function, a class or object from the C++ standard library.
    Examples: cout, cin, ect...

    Code:
    int main(int argc, char *argv[])
    First we declare "main" after wards we declare "argv" in main, as a char *, a pointer to an array of pointers to arrays of chars.


    Yeah! Now you about halfway done, only four more lines of code before we finish.

    Code:
    {
    system("PAUSE");
    return EXIT_SUCCESS;
    }
    Firstly, this in the code in "main" which we declared earlier, you can tell because we declared it and then we have the opening and closing brackets with code inside them. The "system("PAUSE")" means that we launch "PAUSE" as a system command, as you may or may not know Batch has a similar function where "PAUSE" is used. Pause basically just pauses your application and waits for the user to respond, it does this by saying "Hit any key to continue ect.." and it waits for the user to hit a key. So after they hit a key, the program exits and that's where "return EXIT_SUCCESS;" comes into play. After wards if you are using Dev C++ (Like you should be if you are a beginner) hit F9 to compile+run the Console Application that I just explained. After you run it you should see whats in the picture below.
    [attachment=2103]


    Now after you understand the Console Application coding, I will teach you how to make your computer speak. Biggrin

    Firstly we will be using "cout" which I have mentioned earlier. Cout is an object of class "ostream" which represents the standard output stream, not only that but it corresponds to the cstdio stream stdout.

    Code:
    cout << "Hello, this is your computer talking." << endl;
    Go ahead and paste that code into your project like in the picture below.
    [attachment=2104]

    Pretty sweet huh? You just made your computer talk. Now let me explain what it means. After "cout" we have "<<" which just tells the computer that we are about to make it say something and then we have what we want to say in quotation marks "" and after wards we have another set of "<<" to tell the computer that we are finished with what we had to say and then we have "endl" which ends the line and finally a statement terminator ";" to stop the statement.

    Yeah! We finished and now you have the basic knowledge on a Console Application. Please visit any future tutorials that I may make and happy coding!



    Enjoy.

    How To Create A Console Application [C++]
  2. #2
    Cypher's Avatar Kynox's Sister's Pimp
    Reputation
    1358
    Join Date
    Apr 2006
    Posts
    5,368
    Thanks G/R
    0/6
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sigh.

    1. Don't use system("PAUSE"). It's not portable, it's unnecessary, and just plain stupid. If you want to stop the console window from closing do this:
    // Stop window from automatically closing
    wcin.clear();
    wcin.sync();
    wcin.get();

    2. The 'return EXIT_SUCCESS' is unnecessary. The C++ standard dictates that 'main' is special and that the return value may be omitted. In this case it will implicitly return 0 (aka EXIT_SUCCESS).

    3. Your explanation of output is retarded. Cout overloads the '<<' operator in order to feed output. You don't do one to tell it you want to start and one to tell it you want to finish, like all good operator overloads it supports chaining. So this is valid:

    std::cout << "This" << "is" << "me" << "writing" << "one" << "word" << "at" << "a" << "time\n".

    As far as your use of 'std::endl' goes, you've also gotten that wrong.

    std::endl both inserts a newline AND flushes the buffer.

    If you're using buffered output (i.e. if you're using pretty much any modern system in existence) than you want to hold off flushing the buffer as long as possible if speed is at all an issue.

    You're better off using the special newline character.

    Example:

    cout << "Hello, this is your computer talking.\n";

  3. #3
    RedArray's Avatar Corporal
    Reputation
    7
    Join Date
    Nov 2009
    Posts
    24
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sigh again.

    Not to nitpick or "flame" as some may see it is. But would much rather you didn't give people false information.

    int main(int argc, char *argv[])
    First we declare "main" after wards we declare "argv" in main, as a char *, a pointer to an array of pointers to arrays of chars.
    It's not a pointer to an array of pointers to an array of chars. What you wrote makes it seem like argv is actually char** argv[] or char*** argv which is untrue. It's an array of char array's. Which can be written as char** argv or as you had it char* argv[]

    Also why are you including cstdlib? Theres no reason for it to be included for a basic C++ console app.

    Another Edit...Just noticed he is banned after I wrote this.
    Last edited by RedArray; 11-16-2009 at 05:04 PM.

  4. #4
    Cypher's Avatar Kynox's Sister's Pimp
    Reputation
    1358
    Join Date
    Apr 2006
    Posts
    5,368
    Thanks G/R
    0/6
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by RedArray View Post
    Sigh again.

    Not to nitpick or "flame" as some may see it is. But would much rather you didn't give people false information.



    It's not a pointer to an array of pointers to an array of chars. What you wrote makes it seem like argv is actually char** argv[] or char*** argv which is untrue. It's an array of char array's. Which can be written as char** argv or as you had it char* argv[]

    Also why are you including cstdlib? Theres no reason for it to be included for a basic C++ console app.

    Another Edit...Just noticed he is banned after I wrote this.
    Nice, I missed that one.

Similar Threads

  1. How To Create Glider Profiles
    By Gummibär in forum World of Warcraft Guides
    Replies: 7
    Last Post: 06-28-2007, 05:57 AM
  2. How to Enable WoW Console and rebind console key
    By Vladinator in forum World of Warcraft Guides
    Replies: 6
    Last Post: 04-14-2007, 07:54 AM
  3. How to access wow console...
    By Bareno in forum World of Warcraft Exploits
    Replies: 71
    Last Post: 03-20-2007, 02:30 AM
  4. How to create a free guildsite
    By Marlo in forum World of Warcraft General
    Replies: 15
    Last Post: 12-27-2006, 07:33 AM
  5. How To Creat A Macro
    By LightWave in forum World of Warcraft Guides
    Replies: 5
    Last Post: 08-17-2006, 06:58 AM
All times are GMT -5. The time now is 12:06 AM. Powered by vBulletin® Version 4.2.3
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved. User Alert System provided by Advanced User Tagging (Pro) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
Google Authenticator verification provided by Two-Factor Authentication (Free) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
Digital Point modules: Sphinx-based search