[Visual C++] Comment convertir un CString en char* ?

Résolu
Braho Messages postés 4 Date d'inscription mercredi 18 mai 2005 Statut Membre Dernière intervention 26 mai 2005 - 24 mai 2005 à 11:11
ymca2003 Messages postés 2070 Date d'inscription mardi 22 avril 2003 Statut Membre Dernière intervention 3 juillet 2006 - 24 mai 2005 à 11:23
Bonjour,

Je suis en train de faire un programme en architecture MFC sous visual C++. Mais j'ai un léger soucis, je n'arrive pas a convertir un CString en char*. Quelqu'un pourrait il m'éclairer ?

Merci d'avance.

1 réponse

ymca2003 Messages postés 2070 Date d'inscription mardi 22 avril 2003 Statut Membre Dernière intervention 3 juillet 2006 7
24 mai 2005 à 11:23
Un CString peut se convertir automatiquement en const char* (ou LPCTSTR).


Pour passer en char* :


CString str;


char* s = (char*)( LPCTSTR)str;

Le mieux si tu veux obtenir un char* que tu veux modifier c'est d'utiliser GetBuffer/ReleaseBuffer de CString.
3
Rejoignez-nous