title: Time Conversion to 24 hour format cpp
body: <p>I am stuck with this program can anyone please help in converting the 12 hour format to 24 hour format?</p>
  
  <pre><code>#include &lt;bits/stdc++.h&gt;
  using namespace std;
  
  string timeConversion(string s) {
  // Complete this function
  string d,c;
  d=s.substr(8,2);
  if(d=="PM"){
  int a;
  a=stoi(s.substr(0,2));
  a=a+12;
  c=to_string(a);
  }
  s[0]=c[0];
  s[1]=c[1];
  s=s.substr(0,8);
  return s;
  }
  int main() {
  string s;
  cin &gt;&gt; s;
  string result = timeConversion(s);
  cout &lt;&lt; result &lt;&lt; endl;
  return 0;
  }
  
  Sample Input: 7:05:45PM
  
  Sample Output: 19:05:45
  </code></pre>
  
  <p>Now i had edited my code and it is running but can you tell  me better ways to do this code??</p>