FORUM Tom's Hardware » Programmation » C / C++ / Java » Question facile mais petit blocage sur mon code C++
 

Question facile mais petit blocage sur mon code C++

Il y a 421 utilisateurs connus et inconnus. Pour voir la liste des connectés connus, cliquez ici
Ajouter une réponse



 Mot :   Pseudo :  
 
Bas de page
Auteur
 Sujet : Question facile mais petit blocage sur mon code C++
 
Plus d'informations

Bonjour, voici mon code:
Je voudrais ajouter une condition concernant l'exécution de la boucle.Je veux rentrer dans la boucle si solution ne contient aucune lettre.
Comment puis-je coder celà?


Code :
  1. srand( (unsigned) time (NULL) );
  2.  
  3.   for ( int i = 0 ; i < Game::howManyPositions;)
  4.       { int nextValue = rand () % (Game::howManyLetters);
  5.         char theChar = alpha[nextValue];
  6.         // lettre déjà existante?
  7.           if ( ! duplicates && i > 0 )
  8.           {            vector<char>::iterator where =
  9.               find(solution.begin(), solution.end(), theChar);
  10.               if (where != solution.end())
  11.                 continue;
  12.           }
  13.           solution.push_back(theChar);
  14.        
  15.         i++;
  16.    
  17.   }


Après que solution soit rempli,
quand je teste if (solution[0] == ' ');
cout << "l'instruction";, instruction s'affiche alors que solution est rempli.Quelle est mon erreur?

Dautre part quand je lance pour la première fois mon prog, le vector solution est rempli à zéro ce qui est normal mais je ne vois pas comment il est initialisé:
Solution est une variable membre de human.

Human::Human(bool dupes):
Decrypter(dupes), hintCtr(0)

Decrypter::Decrypter(bool dupes):

round(1),
duplicates (dupes)
{
Merci pour vos explications


Message édité par smag le 09-02-2005 à 00:16:36

Profil : Pointeur
Plus d'informations

j'ai pas tout compris...


---------------
Da Bidz Triad©®™: Bidz Interceptor
.:: Smileyz version 4.2 [050625]::. -- Code source disponible sous licence GPL.
[u
XHTML 1.1 certified
Plus d'informations

Code :
  1. if(!solution.size())
  2. {
  3.   for ( int i = 0 ; i < Game::howManyPositions;)
  4.   ....
  5. }



http://www.sgi.com/tech/stl/Vector.html


Aller à :
Ajouter une réponse
  FORUM Tom's Hardware » Programmation » C / C++ / Java » Question facile mais petit blocage sur mon code C++
 

Annonces Google
Publicité