title: timer on counting the total time execution on a program for c++?
body: <p>So I have this following simple program that I would like to have a timer imprinted in the program to count the exact time it takes for the program to execute on the number of n times.</p>
  <pre><code>for (int i=0; i&lt;n; i++){
  for (int j=1; j&gt;=i; j++){
      cout &lt;&lt; &quot;perfecto&quot; &lt;&lt; endl;
  </code></pre>
  <p>I was thinking of using the ctime library to help me out with the timer.</p>
  <pre><code>#include &lt;iostream&gt;
  #include &lt;ctime&gt;
  
  using namespace std;
  
  
  time_t time_1;
  time_t time_2;
  time ( &amp;time_1);
  
  int main(){
  int n=5;
  for (int i=0; i&lt;n; i++){
      for (j=0; j&lt;=i; j++){
          cout &lt;&lt; 'test';
  }
  }
  }
  
  time (&amp;time_2 );
  
  cout&lt;&lt;'time taken for the algorithm :'&lt;&lt;time_2 - time_1 &lt;&lt; seconds &lt;&lt;endl;
  </code></pre>
  <p>Will this work somehow because when I ran this it shows me an error just like this.
  <a href="https://i.stack.imgur.com/2IuYP.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/2IuYP.jpg" alt="enter image description here" /></a></p>
  <p>Is there any other way to do it and is it possible to add a timer when starting the program?</p>