I have to make a program where the user inputs a time in the standard format (hh:mm:ssPM) as a string, then I have to convert it to military time.
I have an idea of how to do it, my idea is to convert the string to a character array by taking each character of the string and turning it into a char, then if the char containing the 'P' or 'A' in PM/AM is a 'P' I would add 12 to the char containing the 'hh' part.
I know I have to use c.str() to convert but I don;t know how exactly, Do I have to create a char array of size 10? Or can I just transfer the character at position 8 of the string to see if the entered time is pm or am?
how would I convert the hh to one integer in order to add 12 to it if it's pm?
@kemort
Thank you, I ended up making a program that works but it ended up being much longer than it needed to be, haha.
@programmer007
That was my first thought but I started solving problems on hackerrank so that I can get better at c++, this particular problem specifically wants to input the time as a string, I guess it's supposed to teach you how to manipulate and extract information from strings