Convert string to int

I am trying to subtract one time from another eg: 16:10 - 09:10. It is a program for calculating wages on an hourly rate. I am inputting the times through the system clock in a string format. I have the times split in to substrings and I want to convert these into integers to turn into minutes. I am trying to use atoi but it doesn't seem to be working, it says cannot convert std::string to const char*
Convert them to seconds, do your arithmetic and convert it back.
Instead of doing...
1
2
std::string example = "05";
atoi(example);

Do
1
2
std::string example = "05";
atoi(example.c_str());

as atoi only accepts C-Like strings.
Be careful. If atoi fails, it returns 0.
And if your string is "0", it will also return 0.
Thing that isn't happening if you use strtoul in the right way, but you can only get positive values.
Topic archived. No new replies allowed.