C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

changer la valeur d'un caractere

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ (French)
View previous topic :: View next topic  
Author Message
Penguin_X
Guest





PostPosted: Tue Nov 02, 2004 12:44 am    Post subject: changer la valeur d'un caractere Reply with quote



Salut. je voudrais changer la valeur d'un caractere. Mais je ne sais
comment.

exemple: bateau.

Je voudrais que mon programme examine chaque lettre de ce mot, et change
la veleur des lettres. Je pourrais crée un tableau avec la valeur de
chacunes des lettres. a=u , b=r, etc, etc ....

@+

penguin_x
Back to top
Fily
Guest





PostPosted: Tue Nov 02, 2004 1:38 am    Post subject: Re: changer la valeur d'un caractere Reply with quote



can you using the instraction IF
..:,

,
,


if (name_variable == 'a')
{
name_variabile=='u'
else if(.........)
..,

,
,
,
,

}


i think understand

my franch is very terrible

i hope so you understand...........

"Penguin_X" <theshadowman21 (AT) hotmail (DOT) com> ha scritto nel messaggio
news:GKAhd.1006$dj2.295943 (AT) news20 (DOT) bellglobal.com...
Quote:
Salut. je voudrais changer la valeur d'un caractere. Mais je ne sais
comment.

exemple: bateau.

Je voudrais que mon programme examine chaque lettre de ce mot, et change
la veleur des lettres. Je pourrais crée un tableau avec la valeur de
chacunes des lettres. a=u , b=r, etc, etc ....

@+

penguin_x



Back to top
Fabien LE LEZ
Guest





PostPosted: Tue Nov 02, 2004 2:47 am    Post subject: Re: changer la valeur d'un caractere Reply with quote



On Mon, 01 Nov 2004 19:44:51 -0500, Penguin_X
<theshadowman21 (AT) hotmail (DOT) com>:

Quote:
Je voudrais que mon programme examine chaque lettre de ce mot, et change
la veleur des lettres.

void ChangeValeurLettre (char& c)
{
// Ceci est un exemple
if (c=='a') c= 'r';
}

int main()
{
std::string mot= "bateau";
std::for_each (mot.begin(), mot.end(), ChangeValeurLettre);
std::cout << mot << endl;
}


Autre solution :

class ChangeValeurLettre
{
public:
typedef std::map ChangeValeurLettre (Correspondances const& correspondances_)
: correspondances (correspondances_) {}
void operator () (char& c) const
{
Correspondances::const_iterator it= correspondances.find (c);
if (it != correspondances.end()) c= (*it).second;
}
private:
Correspondances correspondances;
};

int main()
{
ChangeValeurLettre::Correspondances correspondances;
// Ici, remplissage
corresp['a']= 'r'; // Un exemple

std::string mot= "bateau";
std::for_each (mot.begin(), mot.end(),
ChangeValeurLettre (correspondances));
std::cout << mot << endl;
}




--
;-)

Back to top
James Kanze
Guest





PostPosted: Tue Nov 02, 2004 8:47 pm    Post subject: Re: changer la valeur d'un caractere Reply with quote

Penguin_X <theshadowman21 (AT) hotmail (DOT) com> writes:

Quote:
Salut. je voudrais changer la valeur d'un caractere. Mais je ne sais
comment.

exemple: bateau.

Je voudrais que mon programme examine chaque lettre de ce mot, et
change la veleur des lettres. Je pourrais crée un tableau avec la
valeur de chacunes des lettres. a=u , b=r, etc, etc ....

Voir std::transform. Avec un objet fonctionnel :

char operator()( char ch ) const
{
return table[ ch - CHAR_MIN ] ;
}

--
James Kanze
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Pierre Sémard, 78210 St.-Cyr-l'École, France +33 (0)1 30 23 00 34

Back to top
Penguin_X
Guest





PostPosted: Tue Nov 02, 2004 10:30 pm    Post subject: Re: changer la valeur d'un caractere Reply with quote

Merci pour l'aide précieuse !
Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ (French) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.