Bonjour,
J'ai plusieurs exos en c++ à faire et le problème est que je n'arrive pas à faire une fonction inverse pour inverser l'affichage d'un mot.
Il faut que j'arrive à inverser une chaine avec l'indice 'i' en lui donnant comme valeur i=i-1.
Pour cela, j'ai le droit à deux fonctions
- int longueurDeMaChaine=maChaine.length();
- string unExtrait=maChaine.substr(x,x);
Le résultat doit être du style: jambon-->nobmaj
voici mon programme si vous pourriez m'aider à le compléter:
#include<iostream>
#include<string>
using namespace std;
int inverse(string);
int main()
{
string laChaine;
cout<<"Saisir un mot: ";
cin>>laChaine;
inverse(laChaine);
system("pause");
return 0;
}
int inverse(string laChaine)
{
string unExtrait;
int longChaine;
inverse(laChaine)=" ";
longChaine = laChaine.length();
for (int i=0; i<longChaine; i++)
{
unExtrait = laChaine.substr(i,1);
inverse(laChaine)=inverse(laChaine)+unExtrait;
}
cout<<unExtrait;
}
MERCI.