|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
|
|
#1
|
|||
|
|||
|
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
|
||||
|
||||
|
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().
|
|
#3
|
|||
|
|||
|
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.
|
|
#4
|
||||
|
||||
|
break up the string using strtok(), the delimiter would be ' : '
then convert each token using atoi() do the math and output hope that helps. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > C Programming > String to integer in C++ |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|