Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8621289
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T06:47:13+00:00 2026-06-12T06:47:13+00:00

This program is taken from cplusplus.com #include <iostream> #include <vector> #include <deque> #include <stack>

  • 0

This program is taken from cplusplus.com

#include <iostream>
#include <vector>
#include <deque>
#include <stack>
using namespace std;

int main ()
{
    deque<int> mydeque (3,100);     // deque with 3 elements
    vector<int> myvector (2,200);   // vector with 2 elements

    stack<int> first;               // empty stack
    stack<int> second (mydeque);    // stack initialized to copy of deque

    stack<int,vector<int> > third;  // empty stack using vector
    stack<int,vector<int> > fourth (myvector);

    cout << "size of first: " << (int) first.size() << endl;
    cout << "size of second: " << (int) second.size() << endl;
    cout << "size of third: " << (int) third.size() << endl;
    cout << "size of fourth: " << (int) fourth.size() << endl;

    return 0;
}

What I failed to understand is, why are we mentioning stack<int, vector<int>> i.e. two data types rather than just stack<vector<int>>?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T06:47:15+00:00Added an answer on June 12, 2026 at 6:47 am

    Check out: http://www.sgi.com/tech/stl/stack.html

    Creating a stack with two data type parameters to the template as so stack<T, Sequence> stack;

    is done because the first type parameter is the type of element the stack holds, and the second type parameter is the container type used to implement the stack.

    Using different container types gives you different memory allocations, benefits and drawbacks in terms of speed, etc. It’s just giving you as the consumer more flexibility in terms of the type of implementation you wish to use.

    From that link:

    Stack is a container adaptor, meaning that it is implemented on top of
    some underlying container type. By default that underlying type is
    deque, but a different type may be selected explicitly.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

//This program is taken from http://www.learncpp.com/cpp-tutorial/114-constructors-and-initialization-of-derived-classes/ #include <iostream> using namespace std; class A {
Given below is program for encrypting a string. I had taken this code from
this is a code snippet taken from https://forums.embarcadero.com/message.jspa?messageID=219481 if FileExists(dstFile) then begin Fs :=
I'm trying to use this code which is an example taken from here https://gist.github.com/2383248
This example is taken from the Linux System Programming book, page 88. Code: http://pastebin.com/mEfmHbPP
This is the code taken from http://code.google.com/p/crawler4j/ and the name of this file is
This program taken from a book Pro JavaScript Techniques is used to create hover-like
This example is taken from the Java programming book; 4th Edition. After stumbling upon
I have a program that is counting the frequencies of words taken from a
This code (taken from Learn You A Haskell ): main = do putStr Hey,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.