{"id":1891,"date":"2024-10-10T08:00:00","date_gmt":"2024-10-10T06:00:00","guid":{"rendered":"https:\/\/www.fuhselab.de\/?p=1891"},"modified":"2025-05-28T07:27:33","modified_gmt":"2025-05-28T05:27:33","slug":"hallo-welt-und-variablen","status":"publish","type":"post","link":"https:\/\/www.fuhselab.de\/index.php\/2024\/10\/10\/hallo-welt-und-variablen\/","title":{"rendered":"Hallo Welt und Variablen"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\"><br>Hinter uns liegen 5 C++ Workshops und nun geht die Reise erst richtig los\u2026<\/p>\n\n\n\n<!--more-->\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Das Hallo Welt Programm:<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Der Code wird mit einem gew\u00f6hnlichen Texteditor geschrieben und als cpp-Datei abgespeichert.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#include &lt;iostream&gt;\nint main()\n{\nstd::cout &lt;&lt; \"Hallo, du sch\u00f6ne Welt!\" &lt;&lt; std::endl; \nreturn 0;\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Die Datei sollte hier als \u201challo.cpp\u201c abgespeichert werden.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Variablen in C++:<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Bereits unsere ersten Schritte in die Welt von C++ brachten uns das &#8222;Hallo Welt-Programm&#8220; und eine erste Variable die wir sogar dynamisch per Tastatureingabe gef\u00fcllt haben.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In Zeile 1 wird per include-Befehl die iostream-Bibliothek eingebunden.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In Zeile 2 beginnt mit \u201cint main&#8220; eine Integer-Funktion. Es ist die Hauptfunktion des Programms.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In Zeile 3 steht eine sich \u00f6ffnende geschweifte Klammer.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In Zeile 4 beschreibt &#8222;std::cout&#8220; den Standardausgabe-Strom.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In Zeile 5 wird der Code mit return abgeschlossen.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In Zeile 6 wird die geschweifte Klammer geschlossen.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Die beiden Pfeile oder besser die beiden Spitzklammern vor und hinter der Ausgabe signalisieren, dass der dahinterstehende Text auf die Standardausgabe \u201egeschoben\u201c wird. Das \u201cstd::endl\u201c gibt dann einen Zeilenumbruch aus.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Eingabe und Ausgabe in C++:<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Bisher wurde der Namensraum \u201cstd\u201c immer direkt vor den jeweiligen Befehlen angegeben. Es ist zwar auch m\u00f6glich per \u201cusing namespace std;\u201c diesen Namensraum global anzugeben, doch das soll angeblich schlechter Stil sein. F\u00fcr die bisherigen und auch zuk\u00fcnftigen Workshops verzichten wir also auf diese globale Deklaration.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Nachfolgend noch das erste Beispiel einer Eingabe und Ausgabe per C++ mit Zeilenumbruch:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#include &lt;iostream&gt;\nint main() \n{\nint Ganzzahl;\nstd::cout &lt;&lt; \"Benutzereingabe: \"; \nstd::cin &gt;&gt; Ganzzahl; \nstd::cout &lt;&lt; \"Sie haben \" &lt;&lt; Ganzzahl &lt;&lt; \" eingegeben.\" \n&lt;&lt; std::endl;\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Die beiden Spitzklammern zeigen immer in die jeweilige Zielrichtung. Ausgaben werden mit zwei Spitzklammern erzeugt die nach links zeigen und Eingaben werden mit zwei Spitzklammern erzeugt die nach rechts zeigen.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Schritt f\u00fcr Schritt soll \u00fcber die n\u00e4chsten Artikel ein kleiner Taschenrechner programmiert werden und eine erste kleine Version wurde bereits im C++ Workshop 5 vorgestellt.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Das erste kleine Taschenrechner-Programm:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#include &lt;iostream&gt;\n\nint main()\n{\nint Summand1, Summand2, Ergebnis;\nstd::cout &lt;&lt; \"Benutzereingabe f\u00fcr Addition Zahl1: \";\nstd::cout &lt;&lt; \"Benutzereingabe f\u00fcr Addition Zahl2: \";\nstd::cin &gt;&gt; Summand1 &gt;&gt; Summand2;\nErgebnis = Summand1 + Summand2;\nstd::cout &lt;&lt; Summand1 &lt;&lt; \" + \" &lt;&lt; Summand2\n&lt;&lt; \" = \"\n&lt;&lt; Ergebnis\n&lt;&lt; std::endl;\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><br>Zugegeben die Eingabe ist noch etwas holprig, doch das soll ja auch Schritt f\u00fcr Schritt in den n\u00e4chsten Artikeln verbessert und optimiert werden.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hinter uns liegen 5 C++ Workshops und nun geht die Reise erst richtig los\u2026<\/p>\n","protected":false},"author":1,"featured_media":543,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[33],"tags":[32],"class_list":["post-1891","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-coding-club","tag-coding-club-peine"],"_links":{"self":[{"href":"https:\/\/www.fuhselab.de\/index.php\/wp-json\/wp\/v2\/posts\/1891","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.fuhselab.de\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.fuhselab.de\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.fuhselab.de\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.fuhselab.de\/index.php\/wp-json\/wp\/v2\/comments?post=1891"}],"version-history":[{"count":2,"href":"https:\/\/www.fuhselab.de\/index.php\/wp-json\/wp\/v2\/posts\/1891\/revisions"}],"predecessor-version":[{"id":2850,"href":"https:\/\/www.fuhselab.de\/index.php\/wp-json\/wp\/v2\/posts\/1891\/revisions\/2850"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.fuhselab.de\/index.php\/wp-json\/wp\/v2\/media\/543"}],"wp:attachment":[{"href":"https:\/\/www.fuhselab.de\/index.php\/wp-json\/wp\/v2\/media?parent=1891"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.fuhselab.de\/index.php\/wp-json\/wp\/v2\/categories?post=1891"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.fuhselab.de\/index.php\/wp-json\/wp\/v2\/tags?post=1891"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}