stacks will not work

Hi
im really new to coding so sorry if this is a stupid question.
I need to learn to use stacks for my coursework and when practicing them iv followed the workshop instructions but some reason visual studios is not like it.
i get the same error every time that "stack identifier is undefined"
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28

#include "stdafx.h"
#include <iostream>
#include <string>
#include <stdlib.h>
#include <stack>


class car
{
	int doors;
	int speed;
	bool onFire;

	car()
	{
		doors = 4;
		speed = 65;
		onFire = true;
	}
};


int main()
{

	stack<car> CarStack; // 
Last edited on
1
2
3
4
5
6
7
In function 'int main()': 
26:2: error: 'stack' was not declared in this scope 
26:2: note: suggested alternative: 
In file included from /usr/include/c++/4.9/stack:61:0, 
                      from 5: 
/usr/include/c++/4.9/bits/stl_stack.h:99:11: note:   'std::stack' 
        class stack


Try appending std:: like this std::stack<car>
Use this before main function :
 
using namespace std;

i have used using namespace... just for some reason missed it out in my copy/paste
its the stack<Car> CarStack; that is causing me the issue
@fantomasAlbania

Having using namespace std; is not recommended. In the end the easiest thing to do is just pre-pend std:: to every std thing, as wildblue says. There is plenty written about this all over the internet.

Topic archived. No new replies allowed.