Advertisement
Blizzardo1

A simple HelloWorld Program with Arguments

Dec 11th, 2012
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.31 KB | None | 0 0
  1. // These are the headers you need to include for a simple C++ Program, IOSTREAM being the Standard C++
  2. // header while STDIO is the Standard Input and Output header.
  3. #include <iostream>
  4. #incude <stdio.h>
  5.  
  6. // here we include the Standard Namespace
  7. using namespace std;
  8.  
  9. // This is the Main Body, the Execution of the program!
  10. // Here we have argc and argv, argc being our Argument Counter, while argv being our Argument vector.
  11. // argc counts how many arguments we've passed while argv contains all the data that you pass from the
  12. // console, making it easier to apply switches to better function your program.
  13. int main( int argc, char *argv[] ) {
  14.     // Prints Hello World! and then breaks to a new line
  15.     cout << "Hello World!" << endl;
  16.  
  17.     // This is a for counter, for which our new variable i = 0, and we need to create a condition
  18.     // where argc is the max we can count, and i++ increments by 1 until we meet argc
  19.     for(int i = 0; i < argc; i++)
  20.         // We print the Argument here
  21.         // E.G. Argument 1 of 10: "Hello there!"
  22.         cout << "Argument " << i << " of " << argc << ": \"" << argv[i] << "\"" << endl;
  23.     // Here we print this to let the person know that we're ending the program, and that they need to
  24.     // press a key to continue.
  25.     cout << "WE REACHED AN END! :D" << endl << "Press any key to quit...";
  26.     getchar();
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement