Bonjour,

Je voudrais utiliser une map dans une structure (cf code), mais lorsque j'exécute j'ai une 'segmentation error'. J'imagine que l'objet map n'est pas crée avant le insert mais comme je suis débutant en C++ je vois pas comment le faire. Si qqn a une idée là-dessus....

Merci de votre aide.

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
 
#include <stdio.h>
#include <stdlib.h>
#include <map>
#include <iostream>
 
using namespace std;
 
typedef struct plot {
  int num_plot;
  map<int, float> map_1;
  map<int, float> map_2;
} struct_plot;
 
typedef struct_plot *pt_plot;
 
int main(void) {
   pt_plot plot;
   map<int,float>::iterator it;
   plot=((pt_plot)calloc(1,sizeof(struct_plot)));
 
   plot->map_1.insert(std::pair<int,float>(12,300.32));
   for (it=plot->map_1.begin() ; it != plot->map_1.end(); it++ ){
      cout << (*it).first << " => " << (*it).second << "\n";
   }
   return EXIT_SUCCESS;
}