title: How to convert formatted string HH:MM:SS to seconds in C++
body: <p>I want to convert a string time stamp formatted in HH:MM:SS to seconds only, and then compare it with a number. I have written a prime version of my code in Java, however I separately ask from Scanner as opposed to having a <code>string</code> time. I'm not much familiar with C++ libraries, as I'm a Java guy. Wondering how I can do it in C++? </p>
  
  <p>Make it brief, <code>String s = "1:01:01";</code> and <code>String s2= "3600";</code> I need to know <code>if (s&gt;s2)</code></p>
  
  <pre><code>import java.util.*;
  
  public class Test {
      public static void main(String[] args) {
          Scanner console = new Scanner(System.in);
  
          int hours;
          int mins;
          int secs;
  
          System.out.println("Enter Hours: ");
          hours = console.nextInt();
  
          System.out.println("Enter Minutes: ");
          mins = console.nextInt();
  
          System.out.println("Enter Seconds: ");
          secs = console.nextInt();
  
          int showSecs = (hours * 3600) + (mins * 60) + secs;
  
          System.out.println(hours + ":" + mins + ":" + secs + " in secs are "
                  + showSecs);
  
      }
  }
  </code></pre>