D&C GLug - Home Page

[ Date Index ] [ Thread Index ] [ <= Previous by date / thread ] [ Next by date / thread => ]

Re: [LUG] C++ Question

 

On Thu, 5 Mar 2009, Sam Grabham wrote:

> Hi
>
> I have been trying to pass a string and a number via the command line, and then 
> setting varibles for use later on in the code.
>
> When i pass say 23 as the second param i get a larger number set to 
> "nMinutesIn" variable. If i cout << argv[2]; then i will get the 23 
> value, so if the argv[2] is a char type how do i convert to a int?

atoi() l

At least in C - it's been 10 years since I looked at c++

So:

   nMinutesIn = atoi (argv ([2]) ;

atoi stands for ascii to integer.

there are many other ways, but that's possibly the simplest.

Gordon

>
> I also would be greatfull for any advise for compairing dates, I want to create a 
> funtion that acts like dateadd() function.
>
> I am finding it hard to find c++ generic sample code on the web, As lots of sample 
> code is using windows apis etc.
>
> Anyone know of some good urls?
>
> my problem sample code below:
>
> int main(int argc, char *argv[])
> {
>   struct stat fileInfo;
>   unsigned int nMinutesIn=0;
>   string searchPath="";
>
>    searchPath = string(argv[1]);
>    nMinutesIn = int(argv[2]);
>
>
> Regards
>
>
> Sam

-- 
The Mailing List for the Devon & Cornwall LUG
http://mailman.dclug.org.uk/listinfo/list
FAQ: http://www.dcglug.org.uk/linux_adm/list-faq.html