a and b werent declared in the scope

Write your question here.

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
  #include <iostream>
#include <vector>
using namespace std;

struct mystruct{
	int a;
	int b;
};

void show(const mystruct& actual){
	cout<< a.actual<< " "<< b.actual;
}
int main()
{
	vector<mystruct> vec;

    for(vector<mystruct>::iterator it = vec.begin();it != vec.end();++it){
				show(*it);
		
	}
    cout << "\n";
	return 0;
}

I forgot to write the quiestion:

I want to show the vector<struct>, but the compiler says that a ad b were not declared in teh scope...I think they have the same type...but obviosly they must be differents types...
You're trying to access a.actual... where you really need to access actual.a. Ditto for b.
for god sake!!!

Thanks!!
now I wnat to delete just object which contains a 0...I have done this, but it's not working..

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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
 
#include <iostream>
#include <vector>
using namespace std;

struct mystruct{
	int a;
	int b;
};

void show( const mystruct& actual){
	cout << "\n";
	cout<< actual.a<< " "<< actual.b;
	
}


mystruct copy (mystruct actual){
	cout<<"Enter part a:";
	cin>>actual.a;
	cout << "Enter part b:";
	cin>> actual.b;
	return actual;
}
int main()
{
	vector<mystruct> vec;
	mystruct example;
	string exit;
	while(exit !="exit"){
		
		cout<<"Do you want to leave";
		cin>> exit;
		if(exit != "exit"){
		example = copy(example);
		vec.push_back(example);
		
		}
	}
    
	for(vector<mystruct>::iterator it = vec.begin();it != vec.end();++it){
				show(*it);
		
	}
    cout << "\n";
	return 0;
	
	for (vector<mystruct>::iterator iter = vec.begin();iter != vec.end;){
		
		example = *iter;
		if( a.example or b.example == 0)
			iter = vec.erase(iter);
		else
			++iter;
		
	}
}

Change (48th line)
for (vector<mystruct>::iterator iter = vec.begin();iter != vec.end;)
to
for (vector<mystruct>::iterator iter = vec.begin();iter != vec.end();)
and 51st line:
if( a.example or b.example == 0)
to
if(example.a or example.a == 0)
a and b are members of some object, so that object goes first, as in here example.a
Topic archived. No new replies allowed.