Basically I need to write a program that will ask the user to enter arrival and departure time in the 24 hour format and it needs to calculate the difference between them. I know how to do everything else, but i'm not sure how to make it so that it lets you enter the time.
CodePudding user response:
You can use std::get_time to parse the input into a std::tm structure. You can use std::chrono::system_clock::from_time_t to convert the std::tm object into a time point. You can subtract the time points to calculate the difference.
In C 20, you may streamline the code using std::chrono::parse.
CodePudding user response:
- Validate your input with a regex like this regex time.
- Use Posix time to create arrival and departure objects.
- Use
diffTimeto get the difference. Example here
