Conversion string char[] pas très propre
Bonjour,
J'ai besoin de convertir un string en char[] (je ne veux pas en char*). Pour l'instant je fais ceci:
Code:
1 2 3 4 5 6 7 8 9
| std::string username_string=uneFonction();
char username[255];
int i=0;
if(username_str.size()<255)
{
for(i=0;i<username_str.size();i++)
username[i]=username_str.at(i);
}
username[i]='\0'; |
ça marche mais c'est pas top. J'aimerais ne pas imposer une taille constante à mon tableau de char.
Dans l'idéal
Code:
char username[username_string.size()+1];
Mais on ne peut pas faire cela.
Existe-t-il un autre moyen d'effectuer cetter conversion?
Merci d'avance