Urgent pb C++
riri
-
riri -
riri -
j'ai un soucis avec mon code
mon .h
const int NB_WARNING = 14
std::string _errorLevel[NB_WARNING]
mon .c
....
for (int i=0;i<NB_WARNING;i++){
if ((_errorLevel[i]).length() == 0) {
_errorLevel[i]="test";
cout << i << _errorLevel[i];
}
}
le probleme c'est que mon tableau est toujours vide meme apres l'affectation
pourquoi ?
mon .h
const int NB_WARNING = 14
std::string _errorLevel[NB_WARNING]
mon .c
....
for (int i=0;i<NB_WARNING;i++){
if ((_errorLevel[i]).length() == 0) {
_errorLevel[i]="test";
cout << i << _errorLevel[i];
}
}
le probleme c'est que mon tableau est toujours vide meme apres l'affectation
pourquoi ?
6 réponses
c koi ce std:: qui traine ???
en plus si t'utilise la classe string je te conseil de faire un new.
sinon utilise le char * ca passe mieux.
Bonne prog !!
@++ !!!
en plus si t'utilise la classe string je te conseil de faire un new.
sinon utilise le char * ca passe mieux.
Bonne prog !!
@++ !!!
string _errorLevel[i]=new string("test");
normal
string _errorLevel[i]= // attend un objet de type string
new string("test"); // est un string* (pointeur sur un objet de type string)
donc soit tu écrit
string _errorLevel[i]=string("test");
soit tu changes
1) std::string _errorLevel[NB_WARNING]
en
std::string* _errorLevel[NB_WARNING]
2)cout << i << _errorLevel[i];
en
cout << i << (*_errorLevel[i]);
3) à la fin du prg tu détruit les objets alloués avec new comme c
ceci:
for (int i=0;i<NB_WARNING;i++)
if (_errorLevel[i]!=NULL) {
delete _errorLevel[i];
string _errorLevel[i]= // attend un objet de type string
new string("test"); // est un string* (pointeur sur un objet de type string)
donc soit tu écrit
string _errorLevel[i]=string("test");
soit tu changes
1) std::string _errorLevel[NB_WARNING]
en
std::string* _errorLevel[NB_WARNING]
2)cout << i << _errorLevel[i];
en
cout << i << (*_errorLevel[i]);
3) à la fin du prg tu détruit les objets alloués avec new comme c
ceci:
for (int i=0;i<NB_WARNING;i++)
if (_errorLevel[i]!=NULL) {
delete _errorLevel[i];
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question