Command Line Variable Passing (like in DOS)

This is a discussion on Command Line Variable Passing (like in DOS) within the C++ Programming forums, part of the General Programming Boards category; Good Evening, How is it possible to create programs that can have variables passed to it from the DOS command ...

  1. #1
    Unregistered
    Guest

    Command Line Variable Passing (like in DOS)

    Good Evening,

    How is it possible to create programs that can have variables passed to it from the DOS command line, like with alot of DOS programs (eg: The /p part in dir /p)?

    I figure it might have something to do with that whole "char argv[]" what-not, but I am not sure how to implement it. So if anyone could help with this...?

    Any help would be VERY appreciated.

    Paul

  2. #2
    . Driveway's Avatar
    Join Date
    May 2002
    Posts
    469
    Code:
    #include <iostream.h>
    int main(int argc, char* argv[])
    //argc = number of arguements
    //argv[] = arguments
    {
       for(int i=0;i<argc;i++)
          cout<<"argv["<<i<<"]: "<<argv[i]<<endl;
       cin.get();
       return 0;
    }
    This outputs the arguement and then pauses for you to see them
    argv[0] is always the path of the program
    Last edited by Driveway; 08-31-2002 at 07:35 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. sorting number
    By Leslie in forum C Programming
    Replies: 8
    Last Post: 05-20-2009, 04:23 AM
  2. Need some help...
    By darkconvoy in forum C Programming
    Replies: 32
    Last Post: 04-29-2008, 03:33 PM
  3. passing a structure pointer by value
    By Bleech in forum C Programming
    Replies: 6
    Last Post: 07-11-2006, 05:58 PM
  4. creating class, and linking files
    By JCK in forum C++ Programming
    Replies: 12
    Last Post: 12-08-2002, 01:45 PM
  5. Shut off DOS screen automatically to Windows
    By Unregistered in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 11-08-2001, 06:14 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21