lang:cpp:string
Différences
Ci-dessous, les différences entre deux révisions de la page.
| Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédente | ||
| lang:cpp:string [2019/02/11 00:57] – Ajout de "string_view" root | lang:cpp:string [2025/08/27 13:47] (Version actuelle) – [stringstream] : ajout de "Concaténation de string" root | ||
|---|---|---|---|
| Ligne 14: | Ligne 14: | ||
| </ | </ | ||
| - | [[https://cloud.tencent.com/developer/ask/99437|如何使用C ++编写std :: wstring文件的多平台方式?]] {{ : | + | [[https://stackoverflow.com/questions/37395399/multiplatform-way-to-write-a-stdwstring-into-a-file-in-c|Multiplatform way to write a std:: |
| + | * Conversion entre string et wstring | ||
| + | |||
| + | Sous windows : | ||
| + | |||
| + | <code cpp> | ||
| + | std:: | ||
| + | { | ||
| + | int slength = (int)s.length() + 1; | ||
| + | int len = MultiByteToWideChar(CP_ACP, | ||
| + | std:: | ||
| + | MultiByteToWideChar(CP_ACP, | ||
| + | return r; | ||
| + | } | ||
| + | |||
| + | std::string ws2s(const std:: | ||
| + | { | ||
| + | int slength = (int)s.length() + 1; | ||
| + | int len = WideCharToMultiByte(CP_ACP, | ||
| + | std::string r(len, ' | ||
| + | WideCharToMultiByte(CP_ACP, | ||
| + | return r; | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | [[https:// | ||
| + | |||
| + | ====stringstream=== | ||
| + | |||
| + | ===Concaténation de string=== | ||
| + | |||
| + | <code cpp> | ||
| + | std:: | ||
| + | ss << " | ||
| + | ss.str(); | ||
| + | </ | ||
| + | |||
| + | Ou en utilisant '' | ||
| + | |||
| + | <code cpp> | ||
| + | std::string coucou = " | ||
| + | |||
| + | std:: | ||
| + | </ | ||
| + | |||
| + | ===char=== | ||
| + | |||
| + | Le résultat ne va pas être le même si on donne à '' | ||
| + | |||
| + | <code cpp> | ||
| + | ss << static_cast< | ||
| + | </ | ||
| + | |||
| + | va donner '' | ||
| + | |||
| + | <code cpp> | ||
| + | ss << static_cast< | ||
| + | </ | ||
| + | |||
| + | va donner '' | ||
| + | |||
| + | ====consteval avec std:: | ||
| + | |||
| + | Ce n'est pas possible. Il faut travailler avec les '' | ||
| + | |||
| + | <code cpp> | ||
| + | #include < | ||
| + | #include < | ||
| + | |||
| + | template <class T, std::size_t N> | ||
| + | struct decayable_array : std:: | ||
| + | constexpr operator const T*() const { return this-> | ||
| + | }; | ||
| + | |||
| + | template < | ||
| + | consteval decayable_array< | ||
| + | decayable_array< | ||
| + | |||
| + | for (std:: | ||
| + | data[N - i - 2] = arr[i]; | ||
| + | } | ||
| + | |||
| + | return data; | ||
| + | } | ||
| + | |||
| + | int main() { return strlen(reverse(" | ||
| + | </ | ||
| + | |||
| + | <code asm> | ||
| + | main: | ||
| + | mov eax, 3 | ||
| + | ret | ||
| + | </ | ||
| + | |||
| + | [[https:// | ||
| ====Split==== | ====Split==== | ||
| ===string=== | ===string=== | ||
| Ligne 26: | Ligne 120: | ||
| </ | </ | ||
| - | [[https:// | + | [[https:// |
| ===string_view=== | ===string_view=== | ||
| Ligne 53: | Ligne 147: | ||
| </ | </ | ||
| - | [[https:// | + | [[https:// |
lang/cpp/string.1549843051.txt.gz · Dernière modification : de root
