stacks

This is a discussion on stacks within the C++ Programming forums, part of the General Programming Boards category; I am trying to create a simple stack but the compiler (visual c++ 6.0) is saying that 'stack' is an ...

  1. #1
    Unregistered
    Guest

    Angry stacks

    I am trying to create a simple stack but the compiler (visual c++ 6.0) is saying that 'stack' is an undelcared identifier. I am keying in the source code directly from a text book. Whats wrong
    program:

    #include <iostream>
    #include <stack>

    int main()
    {
    int n;
    double item;
    stack<double>numbers; //this is where I get the error 'stack':undelcared identifier
    cout<<"type number"<<endl
    cin>>n;
    for (int i=0; i<n; i++);
    {
    cin>>item;
    numbers.push(item);
    }

    }

  2. #2
    S­énior Member
    Join Date
    Jan 2002
    Posts
    982
    stack is in the std namespace. You can either do

    using namespace std;

    or

    using std::stack;
    using std::cout;
    using std::cin;
    //etc

    at the top of your code, or prefix each type with std -

    std::stack<double>numbers;
    //etc

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Please Help Me With This Code Of Implementing Stacks
    By raghu_equinox in forum C Programming
    Replies: 3
    Last Post: 10-19-2006, 07:22 AM
  2. ...multiplication using stacks
    By iiwhitexb0iii in forum C Programming
    Replies: 1
    Last Post: 10-09-2006, 01:28 AM
  3. Avioding Stacks
    By LoafOfBread34 in forum C++ Programming
    Replies: 8
    Last Post: 12-08-2004, 05:20 AM
  4. Dumping singly linked list into 2 stacks.
    By strotee76 in forum C++ Programming
    Replies: 5
    Last Post: 05-16-2004, 05:48 PM
  5. Stacks stacks stacks
    By Unregistered in forum C Programming
    Replies: 4
    Last Post: 06-06-2002, 02:01 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21