#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2003
    Posts
    2
    Rep Power
    0

    String to integer in C++


    I am a novice learning C++ was writing a small program in C++ which takes a date as the input in string format which has to be converted into date in integer format. i tried using atio function and i also tried typecasting.is there any other way we can do this.
  2. #2
  3. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,645
    Rep Power
    4248
    Depends entirely on your dev. environment, which you haven't specified. For gcc, you can try using strptime() to convert the string to a struct tm type and then using mktime() to convert that to int (or rather time_t, to be precise). For C++ Builder, there's StrToDate(), StrToTime() and StrToDateTime().
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2003
    Posts
    2
    Rep Power
    0

    string to integerin C++


    Actually the problem is i have to write a simple program which asks the user to enter the time (hh:mm:ss)and reads it as a string variable , passes that string variable to a function which returns the time in seconds.since i am a beginer to C++ i dont know much about it.only now i am learning functions.i think i am working in gcc environment because i use the syntax g++ -Wall <program name> to compile the program.
  6. #4
  7. not a fan of fascism (n00b)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Feb 2003
    Location
    ct
    Posts
    2,756
    Rep Power
    95
    break up the string using strtok(), the delimiter would be ' : '
    then convert each token using atoi()
    do the math and output
    hope that helps.

IMN logo majestic logo threadwatch logo seochat tools logo