title: Using stack from standard template library
body: <p>I just code a small program to transfer a character from a string onto the stack and print it's top value.
  They are just simple codes but with different concept,I would like to ask which one of the code is more efficient and why?</p>
  
  <p>1st code</p>
  
  <pre><code>#include&lt;string&gt;
  #include&lt;iostream&gt;
  #include&lt;stack&gt;
  using namespace std;
  int main(){
     string str ;
     stack&lt;char&gt; s;
     cin &gt;&gt; str ;
     for(int i=0;i&lt;str.size();i++){
         cout &lt;&lt; str[i] &lt;&lt; "\n";
         s.push(str[i]);
         cout &lt;&lt; "Top of the stack " &lt;&lt; s.top() &lt;&lt; endl;}
   cout &lt;&lt; "\n" &lt;&lt; endl;
   return 0;}
  </code></pre>
  
  <p>2nd code   Using Iterator</p>
  
  <pre><code>#include&lt;string&gt;
  #include&lt;iostream&gt;
  #include&lt;stack&gt;
  using namespace std;
  int main(){
     string str ;
     stack&lt;char&gt; s;
     cin &gt;&gt; str ;
     for(string::iterator itr = str.begin();itr!=str.end();itr++){
               cout &lt;&lt; *itr &lt;&lt; "\n";
               s.push(*itr);
               cout &lt;&lt; "Top of the stack " &lt;&lt; s.top() &lt;&lt; endl;}
   cout &lt;&lt; "\n" &lt;&lt; endl;
   return 0;}
  </code></pre>
  
  <p>They are just two simple codes I just want to know which is more efficient way ??</p>