warum funktioniert das?
-
#include <iostream> int main() { std::cout << "♠♣♥♦" << std::endl ; std::cout << "Ω" << std::endl ; std::cout <<"Hello, 世界" << std::endl; std::string str = "Hello, 世界" ; std::cout << str << std::endl; return 0; }ausgeführt hab ich folgendes auf der Konsole




Ω
Hello, 世界
Hello, 世界warum?
und wozu wchar_t wcout wstring usw...ist das schwarze Magie?
-
kurzefrage schrieb:
#include <iostream> int main() { std::cout << "♠♣♥♦" << std::endl ; std::cout << "Ω" << std::endl ; std::cout <<"Hello, 世界" << std::endl; std::string str = "Hello, 世界" ; std::cout << str << std::endl; return 0; }ausgeführt hab ich folgendes auf der Konsole




Ω
Hello, 世界
Hello, 世界warum?
und wozu wchar_t wcout wstring usw...ist das schwarze Magie?
std::cout << "



" << std::endl ;
std::cout << "Ω" << std::endl ;
std::cout <<"Hello, 世界" << std::endl;
std::string str = "Hello, 世界" ;
std::cout << str << std::endl;code noch mal ohne code tag, damit man besser sieht wie er aussieht
-
Den std::wstring braucht man praktisch nie.
Manchmal stimmt der direkte Zugriff nicht ganz ("


"[3]), aber ich hab das noch nie gebraucht.
-
Was gibt str.lenght aus?
-
ohohoho schrieb:
Was gibt str.lenght aus?
Die Länge eines Strings. Wenn bei solchen Zeichen ein
wstringverwendet wird, dann ist es wie erwartet.
-
kurzefrage schrieb:
warum?
ist das schwarze Magie?
Warum nicht? Der Standard schreibt bezüglich Characterset nicht wirklich etwas vor, ausser dass es mindestens bestimmte Zeichen enthalten muss (a-z, A-Z, 0-9 und so weiter).
Wenn dein Compiler UTF-8 String-Literale macht, und dein Betriebssystem auch UTF-8 verwendet, dann ist nicht weiter verwunderlich dass das funktioniert.Andere Compiler werden es anders sehen.
Hier das Ergebnis mit MSVC 2010.
Compilieren:1>------ Build started: Project: vc10test, Configuration: Debug Win32 ------ 1> vc10test.cpp 1>s:\source\vc10test\vc10test.cpp(20): warning C4566: character represented by universal-character-name '\u2660' cannot be represented in the current code page (1252) 1>s:\source\vc10test\vc10test.cpp(20): warning C4566: character represented by universal-character-name '\u2663' cannot be represented in the current code page (1252) 1>s:\source\vc10test\vc10test.cpp(20): warning C4566: character represented by universal-character-name '\u2665' cannot be represented in the current code page (1252) 1>s:\source\vc10test\vc10test.cpp(20): warning C4566: character represented by universal-character-name '\u2666' cannot be represented in the current code page (1252) 1>s:\source\vc10test\vc10test.cpp(21): warning C4566: character represented by universal-character-name '\u03A9' cannot be represented in the current code page (1252) 1>s:\source\vc10test\vc10test.cpp(22): warning C4566: character represented by universal-character-name '\u4E16' cannot be represented in the current code page (1252) 1>s:\source\vc10test\vc10test.cpp(22): warning C4566: character represented by universal-character-name '\u754C' cannot be represented in the current code page (1252) 1>s:\source\vc10test\vc10test.cpp(23): warning C4566: character represented by universal-character-name '\u4E16' cannot be represented in the current code page (1252) 1>s:\source\vc10test\vc10test.cpp(23): warning C4566: character represented by universal-character-name '\u754C' cannot be represented in the current code page (1252) 1> vc10test.vcxproj -> S:\source\vc10test\Debug\vc10test.exe ========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========Ausführen:
???? ? Hello, ?? Hello, ??
-
Darum nimmt man auch keine std::strings
-
xxxxxxxxxxxx schrieb:
Darum nimmt man auch keine std::strings
und was nimmt man dann?
-
kurzefrage schrieb:
xxxxxxxxxxxx schrieb:
Darum nimmt man auch keine std::strings
und was nimmt man dann?
std::string