title: What is the return type of stack.top() and stack.pop() using stack<string> in cpp?
body: <p>I am trying to print the return value of stack.top() using printf() of a stack but it is giving a format mismatch. The code is given below :</p>
  
  <pre><code>int main(){
  
      stack &lt;string&gt; cards;
      char *ch1;
      char ch2[20];
      cards.push("Ace");
      cards.push("King");
      cards.push("Queen");
      cards.push("Jack");
      printf("Number of cards : %ld \n", cards.size());
  
      ch1 = cards.top(); // As sizeof(cards.top()) is 8. error of type conversion
      strcpy(ch2,cards.top()); // cannot convert ‘std::basic_string&lt;char&gt;’ to ‘const char*’
  
      printf("Top of the Stack : %s \n", ch);
      return 0
  }
  </code></pre>
  
  <p>In all examples I saw it was printed using "cout".</p>