473,321 Members | 1,622 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,321 software developers and data experts.

std::stack compilation error

Hi,

I have the following program,

void dfs(struct node * root)
{
if(root == NULL) return;
std::stack <struct node *s;
s.push(root);

while(!s.empty())
{
struct node * temp = s.pop();
printf("%d ",temp->data);
s.push(temp->rptr);
s.push(temp->lptr);
}
}

and i get a error saying,

ro.c: In function `void dfs(node*)':
ro.c:419: `stack' undeclared in namespace `std'

Am i missing something?

Thanks in advance ! ! !
Jun 27 '08 #1
2 1484
Rahul wrote:
void dfs(struct node * root)
{
if(root == NULL) return;
std::stack <struct node *s;
You don't need the struct keyword here.
s.push(root);

while(!s.empty())
{
struct node * temp = s.pop();
That's not how std::stack works. top() and pop() are separate functions:
http://www.cppreference.com/cppstack/index.html
printf("%d ",temp->data);
s.push(temp->rptr);
s.push(temp->lptr);
}
}

and i get a error saying,

ro.c: In function `void dfs(node*)':
ro.c:419: `stack' undeclared in namespace `std'

Am i missing something?
#include <stack?
--
Christian Hackl
Jun 27 '08 #2
On May 5, 8:32 pm, Christian Hackl <ha...@sbox.tugraz.atwrote:
Rahul wrote:
void dfs(struct node * root)
{
if(root == NULL) return;
std::stack <struct node *s;

You don't need the struct keyword here.
s.push(root);
while(!s.empty())
{
struct node * temp = s.pop();

That's not how std::stack works. top() and pop() are separate functions:http://www.cppreference.com/cppstack/index.html
printf("%d ",temp->data);
s.push(temp->rptr);
s.push(temp->lptr);
}
}
and i get a error saying,
ro.c: In function `void dfs(node*)':
ro.c:419: `stack' undeclared in namespace `std'
Am i missing something?

#include <stack?

--
Christian Hackl
Yes, i missed out to include the stack file... Thanks :-)
Jun 27 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Paul | last post by:
I thought this is more of an IE issue but i've had no joy on that group perhaps somebody here will have a clue. If i click a link to a web page embedded in Excel (97 OR 2000) i get the standard...
8
by: Ben | last post by:
Hi all, I implemented a stack in C++ in 2 different ways and I'd like to know which approach is better than the other.. and if there is any difference between the two? I'd also like to know if...
3
by: Pascal Steiss | last post by:
Hi All I don't understand the error that g++ tells me: --- percul3.cpp: In function `void OutputLattice(std::stack<latticeSite, std::deque<latticeSite, std::allocator<latticeSite> > >)':...
5
by: Enos Meroka | last post by:
Hallo, I am a student doing my project in the university.. I have been trying to compile the program using HP -UX aCC compiler, however I keep on getting the following errors. ...
4
by: Christian Christmann | last post by:
Hi, I'd like to store structs on an STL stack. Here is a piece of my code: #inclue <stack> ... struct storeInfo {
2
by: Raider | last post by:
Operator new() must throw std::bad_alloc in no more dynamical memory left, but what standard says about stack? Is there a some way to handle stack overflow? Raider
3
by: janzon | last post by:
Hi I have a really weird bug. An object in my program contains a std::stack<T>. When push is called, the program crashes. To eliminate that the error has to do with what is pushed, I create a...
7
by: DevNull | last post by:
Hello everyone, I decided to pick c++ back up after not really having used it much in 10 years. Just as a point of refference, there was no standard C++ last time I used regularly. Anyways...
1
by: cront | last post by:
All I was able to come up with is this code. I am get confused on how to solve this problem provided a very small amount of Stack operations. /* C++ Primer - 4/e * * Exercise 9.42 *...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.