les tableaux de références ne sont pas conformes.
Bonjour,
Je suis un debutant en C++. Puis, je voudrais savoir comment doit-on faire pour mettre un tableau vector dans une fonction. J'ai cherché depuis longtemps pis j'ai rien trouver. Comment faire pour que ma fonction afficherListe() & ajouterListe() fonctionnent?
vector.h:
Code:
1 2 3 4 5 6 7 8 9 10 11 12
| #ifndef VECTOR_H_INCLUDED
#define VECTOR_H_INCLUDED
#include <string>
#include <vector>
using namespace std;
/* funtion qui affiche la liste des joueur */
void afficherListe(vector<string> const& nom[], vector<int> const& score[])
/*function qui permet de ajouter du monde dans la liste */
void ajouterListe(vector<string>& nom[], vector<int>& score[])
#endif |
vector.cpp
Code:
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
| #include <iostream>
#include <string>
#include <vector>
#include "vector.h"
using namespace std;
void afficherListe(vector<string> const& nom[],vector<int> const& score[])
{
/* Afficher la liste des joueurs avec leur score */
for(int i(0); i < score.size(); i++)
{
cout << nom[i] << " : " << score[i] << endl;
}
}
void ajouterListe(vector<string>& nom[], vector<int>& score[])
{
/* Declarer les variables */
string newNom;
int newScore;
for(int i(0); i<15; i++)
{
/* Enumerer les inscriptions */
cout << i+1 << endl;
/* Si le nombre de i est inferieur au nombre de joueur par defaut*/
if(i < score.size())
{
cout << "Votre pseudo : ";
getline(cin,newNom);
nom[i] = newNom;
cout << "Votre score : ";
cin >> newScore;
score[i] = newScore;
cout << endl;
cin.ignore();
}
/* Si le nombre de joueur depasse le nombre de personne par defaut */
if(i >= score.size())
{
cout << "Votre pseudo : ";
getline(cin,newNom);
nom.push_back(newNom);
cout << "Votre score : ";
cin >> newScore;
score.push_back(newScore);
cout << endl;
cin.ignore();
}
}
cout << endl;
} |
main.cpp
Code:
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
| #include <iostream>
#include <vector>
#include <string>
#include "vector.h"
using namespace std;
int main()
{
/* Declarer les variables */
vector<string> nom(10, "vide");
vector<int> score(10, 0);
/* Les Actions */
ajouterListe(nom,score);
afficherListe(nom,score);
system("PAUSE");
nom.pop_back();
nom.pop_back();
nom.pop_back();
nom.pop_back();
nom.pop_back();
nom.pop_back();
nom.pop_back();
nom.pop_back();
nom.pop_back();
nom.pop_back();
score.pop_back();
score.pop_back();
score.pop_back();
score.pop_back();
score.pop_back();
score.pop_back();
score.pop_back();
score.pop_back();
score.pop_back();
score.pop_back();
afficherListe(nom,score);
system("PAUSE");
return 0;
} |