#include <sstream> // ... // input = "10:45 pm" std::stringstream buffer(input); int iHours, iMinutes; char c; buffer >> iHours >> c >> iMinutes;