Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Issue with stl vector use

3 views
Skip to first unread message

postdt user

unread,
Aug 24, 2009, 3:23:12 PM8/24/09
to info...@gnu.org
Hi,
 
I have a C++ program which uses stl vector to implement a Stack,
a simple program for proof of concept purpose.
My environment is eclipse + cdt6 + cygwin+ gcc 4.3.2+windows xp
when I run it inside eclipse or in cygwin (all in windows xp), I got nothing on screen.
I mean  I can't even see the Starting the process: print out.
 
But when I run it inside vs.net 2008, it worked.
I also tried it on solaris with gcc 3.4.6, it worked too.
So I think it might be issue with setting up with cygwin, so I post it here.
 
Thanks for help.
 
Here's the code:
 
///// stack1.h /////

#include

<vector>

#include

<stdexcept>

template

<class T>

class

Stack

{

private

:

std::

vector<T> elems;

public

:

 

void push(T const&);

void pop();

T top() const;

bool empty() const

{

return elems.empty();

}

Stack();

~Stack()

{

std::cout <<

"destructor called." << std::endl;

}

};

template

<class T>

void

Stack<T>::push(T const& elem)

{

std::cout <<

"push is called: " << std::endl;

elems.push_back(elem);

}

template

<class T>

void

Stack<T>::pop()

{

if (elems.empty())

{

throw std::out_of_range("Stack<>::pop(): empty stack");

}

elems.pop_back();

}

template

<class T>

T

Stack<T>::top() const

{

if (elems.empty())

{

std::cout <<

"empty stack" << std::endl;

throw std::out_of_range("Stack<>::top(): empty stack");

}

return elems.back();

}

 

template

<class T>

Stack<T>::Stack

()

{

std::cout <<

"Default constructor called.." << std::endl;

}
 
 
////// stack1test.cpp ////////
 

#include

<iostream>

#include

<string>

#include

<cstdlib>

#include

"stack1.h"

int

main()

{

try

{

std::cout <<

"Starting the process: " << std::endl;

Stack<int> intStack;

// Stack<std::string> stringStack;

std::cout <<

"Is empty: " << intStack.empty() << std::endl;

intStack.push(7);

int x = intStack.top();

std::cout << x << std::endl;

}

catch
(std::exception const& ex)

{

std::cout <<

"Exception: " << ex.what() << std::endl;

return EXIT_FAILURE;

}

}
 
//// end of program ///////////
 


Hotmail® is up to 70% faster. Now good news travels really fast. Try it now.
0 new messages