Hi all,
I am storing some objects in the list and the i am trying to access them one by one. Each object consists of two strings and one integer.
The problem is that i cannot access these objects through the iterator.
1.How can i access these objects?
#include <stdlib.h>
#include <iostream>
#include <map>
#include <list>
using namespace std;
class A{
public:
string x;
string y;
int z;
};
list<A> G_QUERY_LIST;
list<A>::iterator it;
void create_new_query()
{
string name;
string query;
string results;
cout << "Please enter a name for this query: ";
cin >> name;
cout << "Please enter the query you want to execute: ";
cin >> query;
A ena;
ena.x = name;
ena.y = query;
G_QUERY_LIST.push_back(ena);
}
int main() {
create_new_query();
create_new_query();
cout << "mylist contains:";
for (it=G_QUERY_LIST.begin(); it!=G_QUERY_LIST.end(); it++)
cout<< *it.ena.x;
cout << endl;
return 0;
}
#include <stdlib.h>
#include <iostream>
#include <map>
#include <list>
using namespace std;
class A{
public:
string x;
string y;
int z;
};
list<A> G_QUERY_LIST;
list<A>::iterator it;
void create_new_query()
{
string name;
string query;
string results;
cout << "Please enter a name for this query: ";
cin >> name;
cout << "Please enter the query you want to execute: ";
cin >> query;
A ena;
ena.x = name;
ena.y = query;
G_QUERY_LIST.push_back(ena);
}
int main() {
create_new_query();
create_new_query();
cout << "mylist contains:";
for (it=G_QUERY_LIST.begin(); it!=G_QUERY_LIST.end(); it++)
cout<< *it.ena.x;
cout << endl;
return 0;
}
To copy to clipboard, switch view to plain text mode
Many thanks in advance.
Bookmarks