Bonjour,

Je suis nouveau avec les STL. Est-ce que quelqu'un pourrait m'expliquer le pourquoi du second paramètre (le code complet est au bas de la page) dans:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
set<const char*, ltstr> A(a, a + sizeof(a)/sizeof(a[0]) );
Même chose pour le 3e paramètre dans :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
copy(A.begin(), A.end(), ostream_iterator<const char*, char>(cout, " ") );

Code original de Phil Ottewell's STL Course - http://www.pottsoft.com/home/stl/stl.htmlx

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
struct ltstr
{
  bool operator()(const char* s1, const char* s2) const
  { return strcmp(s1, s2) < 0; }
};
 
int main( int argc, char *argv[] )
{
  const char* a[] = { "Gray", "Pete", "Oggy", "Philip", "JAF", "Simon", "Nick",
                      "Elliott", "Roy", "David", "Tony", "Nigel" };
  const char* b[] = { "Sandy", "John", "Andrzej", "Rob", "Phil", "Happy",
                      "Elliott", "Roy", "David", "Tony", "Nigel" };
 
  set<const char*, ltstr> A(a, a + sizeof(a)/sizeof(a[0]) );
  set<const char*, ltstr> B(b, b + sizeof(b)/sizeof(b[0]) );
  set<const char*, ltstr> C;
 
  cout << "Set A: ";
  copy(A.begin(), A.end(), ostream_iterator<const char*, char>(cout, " ") );