Article ID: 158040 - Last Review: July 12, 2005 - Revision: 4.1 How to use the stack::top and stack::empty STL functions in Visual C++This article was previously published under Q158040 Note Microsoft Visual C++ .NET 2002 and Microsoft Visual C++ .NET 2003 support both the managed code model that is provided by the Microsoft .NET Framework and the unmanaged native Microsoft Windows code model. The information in this article applies only to unmanaged Visual C++ code. On This PageSUMMARY The sample code below illustrates how to use the stack::top
and stack::empty STL functions in Visual C++. MORE INFORMATIONRequired headerPrototypeDescriptionThe top function returns the topmost element of the stack. You should ensure that there are one or more elements on the stack before calling the top function. The first version of the top function returns a reference to the element of the top of the stack, allowing you to modify the value. The second function returns a constant reference, ensuring that you don't accidentally modify the stack.The empty function returns true if there are no elements in the stack. If there are one or more elements, the function will return false. You should use the empty function to verify that there are elements left on the stack before calling the top function. Sample codeREFERENCES For more information about stack::top and stack::empty, visit
the following Microsoft Developer Network (MSDN) Web site: http://msdn.microsoft.com/en-us/library/90t04h29.aspx
(http://msdn.microsoft.com/en-us/library/90t04h29.aspx)
APPLIES TO
| Article Translations
|

Back to the top
