Results 1 to 3 of 3

Thread: Input from command line in c++

  1. #1
    Join Date
    Apr 2011
    Beans
    7
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Input from command line in c++

    I am new to programming and am trying to create a program that takes two numbers from the command line (wind speed and outside temperature), runs them through a few calculations and spits out a number (wind chill). I would like to take input in this sort of style:

    Code:
     ./wind_chill -w 12 -t -7
    I must be able to use negative numbers for the temperature variable.

    So, how would one take the "-w 12 -t -7" part and define them as variables for further use?

  2. #2
    Join Date
    Nov 2009
    Beans
    1,081

    Re: Input from command line in c++

    If your textbook says nothing about argument passing, look up the subject in K&R -- it's argc/argv.

  3. #3
    Join Date
    Jun 2007
    Location
    Maryland, US
    Beans
    6,288
    Distro
    Kubuntu

    Re: Input from command line in c++

    Quote Originally Posted by Some Penguin View Post
    If your textbook says nothing about argument passing, look up the subject in K&R -- it's argc/argv.
    Yes, and coupled with getopt() it should make it fairly trivial to parse the command line options.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •