Simple <stack> problem

dbnewbie used Ask the Experts™
When I compile the code below in VC++ 6.0, I get 7 warnings. I would like to know why I am getting these warnings, what they mean, and what can I do to get rid of them.

#include <string>
#include <stack>
#include <iostream>
using namespace std;

void main() {
     string y[5];     // string can hold up to 5 elements (subscript 0-4), contains NULL by default
     y[0] = "92";     // puts "92" in y[0]
     y[1] = "7";          // puts "7"  in y[1]
     y[2] = "+";          // puts "+"  in y[2]
     y[3] = "6";          // puts "6"  in y[3]
     y[4] = "*";          // puts "*"  in y[4]

     stack <string> stack_contents;

     // enter all elements of array into stack
     for (int i = 0; i < 5; i++)

     // output to console the contents of the stack
     while (! stack_contents.empty()){
          cout << << endl;
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
perhaps u would like to point out the warnings?

coz i couldn't find any...

i heard that VC has a habit of letting a variable declared in a loop to exist beyond the loop, wonders whether that was the case?

Add the following line before you #include's

#pragma warning(disable: 4786)
The warning you're getting is a problem with VC++ having a 255 charactor limit for debug identifier.
This is a problem with VC++, and not a problem with your code.

To remove the warnings just add "#pragma warning(disable: 4786)" to the top of your code.

This will stop the compiler from generating the warnings.
OWASP: Threats Fundamentals

Learn the top ten threats that are present in modern web-application development and how to protect your business from them.

Most of the time I have never bother paying any attention to warnings becaues .exe is generated and program is able to run.
If you want to remove warnings the solution by Axter may work.
Many time I got warning because of not writing .h extension but if you choose to write.
#include <string.h>
#include <stack.h>
#include <iostream.h>
Please remove:
using namespace std; otherwise it will produce error.

One more thing, putting #include <iostream.h> first is good practice. (just suggestion !!!)

Best regards,

>> I have never bother paying any attention to warnings

They can give some good clues on (potential) bugs.

>>#include <iostream.h>
>>using namespace std; otherwise it will produce error.

You should not be using this header in the first place.  It's not part of the C++ standard.
Use only <iostream>

You can use <string.h>, because that is part of the C++ standard.


Thanks, this answers my questions.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial