summaryrefslogtreecommitdiffstats
path: root/contents/wissen/cpp-tutorial/09-strings.php
diff options
context:
space:
mode:
Diffstat (limited to 'contents/wissen/cpp-tutorial/09-strings.php')
-rw-r--r--contents/wissen/cpp-tutorial/09-strings.php67
1 files changed, 67 insertions, 0 deletions
diff --git a/contents/wissen/cpp-tutorial/09-strings.php b/contents/wissen/cpp-tutorial/09-strings.php
new file mode 100644
index 0000000..2630176
--- /dev/null
+++ b/contents/wissen/cpp-tutorial/09-strings.php
@@ -0,0 +1,67 @@
+<?php
+ $author = 'Jakob und Matthias';
+ $pathToRoot = '../../../';
+?>
+<?php
+ include($pathToRoot . 'includes/firstinclude.inc.php');
+ include($pathToRoot . 'includes/header.inc.php');
+ include($pathToRoot . 'includes/mainmenu.inc.php');
+
+ include($pathToRoot . 'sidebars/wissen/cpp.inc.php');
+?>
+
+<div id="inhalt">
+ <h2>
+ 9. Strings
+ </h2>
+ <p>
+ <code style="white-space:pre">
+#include &lt;iostream&gt;
+#include &lt;string&gt;
+
+int main()
+{
+ std::string s;
+ std::string s2(&quot;Text&quot;);
+
+ // Ausgabe
+ std::cout &lt;&lt; s2 &lt;&lt; std::endl;
+
+ // Eingabe
+ std::cout &lt;&lt; &quot;Gib einen Text ein.&quot; &lt;&lt; std::endl;
+ std::cin &gt;&gt; s;
+
+ std::cout &lt;&lt; &quot;&quotDas war dein Text: &quot; &lt;&lt; s &lt;&lt; std::endl;
+
+ std::cout &lr;&lt; &quot;1. Buchstabe: &quot; &lt;&lt; s[0] &lt;&lt; std::endl;
+
+ std::cout &lt;&lt; &quot;Dein Text ist so lang: &quot; &lt;&lt; s.length() &lt;&lt; std::endl;
+
+ // Hier wird ein Buchstabe geändert
+ s2[2] = 's';
+ std::cout &lt;&lt; s2 &lt;&lt; std::endl;
+
+ // Und hier einer angefügt
+ s2 += &quot;s&quot;;
+ std::cout &lt;&lt; s2 &lt;&lt; std::endl;
+}
+
+ </code>
+ </p>
+ <p>
+ Jetzt müssen wir neben iostream auch die Datei string einbinden, da wir den String nutzen wollen.
+ </p>
+ <p>
+ Mit Klammern kann man sie mit einem Text initialisieren. Man kann wie in Arrays auf einzelne Buchstaben zugreifen.
+ Man darf dabei natürlich nicht über das Ende des Strings hinaus, daher kann man die Länge mit der length()-Methode bestimmen
+ </p>
+<h3>Aufgabe:</h3>
+ <p>
+Schreibe ein Programm, das Strings verwendet!
+ </p>
+</div>
+
+<?php
+ include($pathToRoot . 'includes/footer.inc.php');
+ include($pathToRoot . 'includes/lastinclude.inc.php');
+?>