bonjour,comment je peux concaténer deux char
exemple
char c1,c2;
merci
Version imprimable
bonjour,comment je peux concaténer deux char
exemple
char c1,c2;
merci
Avec une std::string ?
bonjour,
avec la fonction strcat
non ça marche que pour les char* et pas les char :cry:
voila un exemple
char a1=char(1);
char a2=char(2);
voila
merci
std::string result(2); me renvoie un erreur
error C2664: '__thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::std::basic_string<char,struct std::char_traits<char>,class s
td::allocator<char> >(const class std::allocator<char> &)' : cannot convert parameter 1 from 'const int' to 'const class std::allocator<char> &'
Reason: cannot convert from 'const int' to 'const class std::allocator<char>'
No constructor could take the source type, or constructor overload resolution was ambiguous
C'est normal, on ne peut pas construire une chaîne de n caractères sans préciser quels vont être ces caractères.
Mais j'avoue que j'écrirais plus naturellement :Code:std::string result(2, '?');
Code:
1
2
3 std::string result; result += c1; result += c2;