Bonjour,
débutant dans le langage C++, je me permets de vous faire part du problème qui me préoccupe : il s'agit de l'intégration d'une fonction.
voici le code source :
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
|
#include <iostream>
#include <string>
#include <ctime>
#include <cstdlib>
#include <vector>
#include <fstream>
using namespace std;
string melange(string mot)
{
char tampon;
int nbAleatoire(0);
for (int i(0) ; i < mot.size() ; i++)
{
nbAleatoire = rand() % mot.size();
tampon = mot[i];
mot[i] = mot[nbAleatoire];
mot[nbAleatoire] = tampon;
}
return mot;
}
int main()
{
srand (time (0));
string ligne, melange;
char tampon;
int nbAleatoire;
//string mot("okidoki");
string const nomFichier("C:/Documents and Settings/SysMic/Mes documents/Langage C++/Mode DICO mot Mystere/dico/dico.txt");
ifstream selectionMot(nomFichier.c_str());
if (selectionMot)
{
// for (int i(0); i< rand() % 323577 ; i++)
//{
// getline(selectionMot , ligne);
//}
cout << "Donnez mot" << endl;
cin >> mot;
mot = melange(mot);
cout << mot;
}
else
{
cout << "ERREUR : Impossible d'ouvrir le fichier." << endl;
}
return 0;
} |
Si je fais ceci, j'ai ce message d'erreur:
C:\...\main.cpp|44|error: no match for call to '(std::string) (std::string&)'|
Alors que cette même fonction fonctionne très bien avec un autre programme.
Par contre, si je n'intègre pas de fonction et écrit les procédure de mélange directement dans le main, je n'ai pas de problème.
Merci pour les réponses que vous m'apporterez.
Partager