S
Suneeel
Hi All,
I'm having trouble with iterating through an STL map.
Firstly, for an empty map, will map.begin() be equal to map.end()?
If this is true, the program should not be entering the while loop to
delete the map's contents...
But, it does, thus causing a segmentation fault when I try to delete..
Is this hapening because the map is empty?
I'm running CentOS, using g++ (GCC) 3.4.5 20051201 on linux kernel
2.6.9-34.EL
This is the code:
#include <stdio.h>
#include <map>
using namespace std;
typedef struct
{
char *data;
}data_type;
typedef map<int ,data_type*> map_type;
int main()
{
map_type my_map;
map_type::iterator it = my_map.begin();
data_type *data_item;
while(it != my_map.end());
{
data_item = it->second;
delete data_item->data;
delete data_item;
printf("\nPass");
it++;
}
my_map.clear();
}
I'm having trouble with iterating through an STL map.
Firstly, for an empty map, will map.begin() be equal to map.end()?
If this is true, the program should not be entering the while loop to
delete the map's contents...
But, it does, thus causing a segmentation fault when I try to delete..
Is this hapening because the map is empty?
I'm running CentOS, using g++ (GCC) 3.4.5 20051201 on linux kernel
2.6.9-34.EL
This is the code:
#include <stdio.h>
#include <map>
using namespace std;
typedef struct
{
char *data;
}data_type;
typedef map<int ,data_type*> map_type;
int main()
{
map_type my_map;
map_type::iterator it = my_map.begin();
data_type *data_item;
while(it != my_map.end());
{
data_item = it->second;
delete data_item->data;
delete data_item;
printf("\nPass");
it++;
}
my_map.clear();
}