Conversion String -> WCHAR*

seb2086 Messages postés 96 Date d'inscription lundi 25 avril 2005 Statut Membre Dernière intervention 1 février 2010 - 21 juil. 2005 à 09:40
cs_jeron Messages postés 29 Date d'inscription lundi 30 juin 2003 Statut Membre Dernière intervention 25 juillet 2014 - 7 oct. 2011 à 13:20
Quelqu'un saurait-il comment convertir une variable de type String en WCHAR* ?
A voir également:

15 réponses

cs_jeron Messages postés 29 Date d'inscription lundi 30 juin 2003 Statut Membre Dernière intervention 25 juillet 2014 2
7 oct. 2011 à 13:17
et comment convertir un string en const wchar_t*

comment convertir un string en wchar_t * ?

#include <string.h>
#include <wchar.h>

void wtoc(wchar_t *toConvert, char *str) {
int count = 0;
int len = wcslen(toConvert);

for(; count < len; count++) {
str[count] = (char) toConvert[count];
}
}

void ctow(const char *toConvert, wchar_t *wstr) {
int count = 0;
int len = strlen(toConvert);

for(; count < len; count++) {
wstr[count] = (wchar_t) toConvert[count];
}
}

void convert(wchar_t wstr[20]) {
char copy[20];
wtoc(wstr, copy);
printf("covertion %s\n";, copy); //élimier cela si vous voulez que ce soit plus clair
}

int main() {
string phrase = "exemple a convertir";
const char *Fichier = new char[phrase.size()+1];
Fichier = phrase.c_str(); //


wchar_t wstr[20];
ctow(Fichier, wstr);
convert(wstr);

cout<< wstr <<"contient la phrase.Elle à été convertit en const wchart * !" << endl;
return 1;
}
1
Rejoignez-nous