-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
192 lines (139 loc) · 4.44 KB
/
main.cpp
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
#include <iostream>
#include <string>
#include <vector>
#include "include\String.h"
#include "testString.h"
using namespace std;
int main()
{
/* Essai avec std::string
string str = "chaine";
cout << "Test avec le string " << str << endl;
cout << "Troisieme caractere: " << str.at(2) << endl;
cout << "Position du caractere 'i': " << str.find('i') << endl;
cout << "Position de la chaine \"ain\": " << str.find("ain") << endl;
//*/
String s = "chaine";
/*
String str ("chaine");
String s = str;
//*/
//String s ("chaine");
//String ain = "ain";
String ain = s.substring(2, 4);
String aine = s.substring(2);
cout << "Test avec le string " << s << endl;
cout << "Troisieme caractere: " << s.charAt(2) << endl;
cout << "Position du caractere 'i': " << s.indexOf('i') << endl;
cout << "Sous-chaines: " << ain << " " << aine << endl;
cout << "Position de la chaine \"ain\": " << s.indexOf("ain") << endl;
cout << "Position de la chaine \"ain\": " << s.indexOf(ain) << endl;
// Pas besoin d'implémenter clear. Apparamment, cette méthode n'existe pas dans Arduino.
s.clear();
cout << "s.clear(): " << s << "." << endl << endl;
//* Fonctions de test
toutTester();
//*/
//* Test uint8_t
uint8_t octet = 0b11011010;
String chaineOctet(octet);
cout << chaineOctet << endl;
byte octet2 = 108;
String chaineOctet2 = "";
chaineOctet2.concat(octet2);
cout << chaineOctet2 << endl;
//*/
/* Test concat
String s3 = "double";
s3.concat(57.4132);
String s4 = "double";
s4.concat(-0.83716000000);
String s5 = "double";
s5.concat(9214.603781820575872085);
cout << s3 + " " + s4 + " " + s5 << endl;
//*/
/* Test toInt()
String strInt1 = "12345";
String strInt2 = "123foo";
cout << "12345 + 1 = " << strInt1.toInt() + 1 << endl;
cout << "123foo + 1 = " << strInt2.toInt() + 1 << endl;
//cout << "chaine + 1 = " << s.toInt() + 1 << endl; // Lance l'exception std::invalid_argument.
//*/
/* Test remove()
String chaineACouper = "anticonstitutionnellement";
String coupee1 = chaineACouper;
String coupee2 = chaineACouper;
coupee1.remove(3);
coupee2.remove(3, 4);
cout << coupee1 << " " << coupee2 << endl;
//*/
/* Test size
String chaineDeTaille = "taille";
cout << "Taille de \"taille\": " << chaineDeTaille.length() << endl;
//*/
/* Test compareTo()
String str1 = "affaire";
String str2 = "patente";
cout << "str1.compareTo(str2): " << str1.compareTo(str2) << endl;
cout << "str2.compareTo(str1): " << str2.compareTo(str1) << endl;
//*/
/* Test +=
String str1 = "affaire";
String str2 = "patente";
str2 += str1;
cout << str2 << endl;
//*/
/* Test +
String str1 = "affaire";
String str2 = "patente";
String somme = str1 + str2;
cout << "str1 + str2: " << somme << endl;
// Pour vérifier que les chaînes originales sont inchangées
cout << "str1: " << str1 << endl;
cout << "str2: " << str2 << endl;
//cout << "\"essai\" + \"tentative\": " << "essai" + "tentative" << endl;
cout << str1 + "essai" << endl;
cout << "tentative" + str2 << endl;
cout << String("cossin") + "machin" << endl;
//*/
/* Essai de new avec String*
String* sp = new String("chaine");
cout << "Pointeur de String: " << *sp << endl;
delete sp;
cout << "Suppression du pointeur avec delete." << endl;
cout << "Pointeur de String: " << *sp << endl;
sp = 0;
cout << "Mise a zero du pointeur." << endl;
/* Fait planter le programme.
cout << "Pointeur de String: " << *sp << endl;
//*/
/* Essai de new avec vector<String*>
vector<String*> strvec = vector<String*>();
const int n = 10000000;
for(unsigned int i=0; i<n; i++)
{
strvec.push_back(new String("chaine"));
}
for(unsigned int i=0; i<10; i++)
{
cout << i << " " << *strvec.at(i) << endl;
}
String a;
cin >> a; // Pour arrêter le programme
// Essai du destructeur
for(unsigned int i=0; i<n; i++)
{
delete strvec.at(i);
}
for(unsigned int i=0; i<10; i++)
{
cout << i << " " << *strvec.at(i) << endl;
}
cin >> a; // Pour arrêter le programme
cout << a << endl;
//*/
/* L'assertion *sp != "mot" échoue après le test du vecteur.
allouerMemoireString();
//*/
return 0;
}