March 18th, 2003, 10:45 PM
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.
March 18th, 2003, 11:32 PM
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().
March 19th, 2003, 02:43 PM
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.
March 19th, 2003, 08:25 PM
break up the string using strtok(), the delimiter would be ' : '
then convert each token using atoi()
do the math and output
hope that helps.