Bonjour,

j'ai voulu faire un petit programme. Ce programme, au niveau conceptuel est tout moisi. j'utilise gets, je mélange du c et du C++, bref, ce n'est absolument pas la question.

Le truc c'est que je reçois une erreur de compilation, et je ne sais pas d'où elle vient, à part que c'est lié à la STL.

Est-ce possible que ce soit dû à une mauvaise installation des bibliothèques ?


je compile avec gcc sous ubuntu 9.04, sur les ordi de mon école.

voici le code :

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
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
 
#include <vector>
 
#include <cstdio>
 
#include <cstdlib>
#include <cstring>
 
#include <algorithm>
#include <iterator>
 
 
 
int main() {
 
	char buf[16000];
 
	std::vector<int> v1, v2, v3;
 
 
 
	while (!feof(stdin)) {
 
		gets(buf);
 
		int n;
 
		char * pch = strtok(buf, " ");
 
		//read number of terms
 
		n=atoi(pch);
 
 
 
		//take the first out of loop
 
		pch = strtok(NULL, " ");
 
		v1.push_back( atoi(pch));
 
 
 
		for (int i=1; i<n ; i++) {
 
			pch = strtok(NULL, " ");
 
			v1.push_back( atoi(pch));
 
			v2.push_back( abs(v1[i] - v1[i-1]));
 
			v3.push_back(i);
 
		}
 
		bool result = std::equal(v2.begin(), v2.end(), v3.begin());
 
		if ( result  )
 
			puts("Jolly\n");
 
		else
 
			puts("Not Jolly\n");
 
 
 
		v1.clear();
 
		v2.clear();
 
		v3.clear();
 
	}
 
 
 
	return 0;
 
}
J'obtiens ces erreurs à la compilation :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
 
$ gcc -o jolly jolly.cpp -Wall
/tmp/ccOhpCmr.o: In function `main':
jolly.cpp:(.text+0x5a): warning: the `gets' function is dangerous and should not be used.
/tmp/ccOhpCmr.o: In function `std::vector<int, std::allocator<int> >::_M_check_len(unsigned int, char const*) const':
jolly.cpp:(.text._ZNKSt6vectorIiSaIiEE12_M_check_lenEjPKc[std::vector<int, std::allocator<int> >::_M_check_len(unsigned int, char const*) const]+0x36): undefined reference to `std::__throw_length_error(char const*)'
/tmp/ccOhpCmr.o: In function `__gnu_cxx::new_allocator<int>::allocate(unsigned int, void const*)':
jolly.cpp:(.text._ZN9__gnu_cxx13new_allocatorIiE8allocateEjPKv[__gnu_cxx::new_allocator<int>::allocate(unsigned int, void const*)]+0x24): undefined reference to `std::__throw_bad_alloc()'
jolly.cpp:(.text._ZN9__gnu_cxx13new_allocatorIiE8allocateEjPKv[__gnu_cxx::new_allocator<int>::allocate(unsigned int, void const*)]+0x32): undefined reference to `operator new(unsigned int)'
/tmp/ccOhpCmr.o: In function `__gnu_cxx::new_allocator<int>::deallocate(int*, unsigned int)':
jolly.cpp:(.text._ZN9__gnu_cxx13new_allocatorIiE10deallocateEPij[__gnu_cxx::new_allocator<int>::deallocate(int*, unsigned int)]+0xd): undefined reference to `operator delete(void*)'
/tmp/ccOhpCmr.o:(.eh_frame+0x12): undefined reference to `__gxx_personality_v0'
collect2: ld a retourné 1 code d'état d'exécution