PDA

View Full Version : Input from command line in c++



wardo1254
December 11th, 2012, 02:29 AM
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:


./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?

Some Penguin
December 11th, 2012, 06:02 AM
If your textbook says nothing about argument passing, look up the subject in K&R -- it's argc/argv.

dwhitney67
December 11th, 2012, 01:00 PM
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.