From 05c27f1304632d39243d48504560de4f5c9df822 Mon Sep 17 00:00:00 2001 From: MuedeHydra Date: Wed, 26 Nov 2025 14:40:22 +0100 Subject: [PATCH] add output and git --- src/informatik_3.typ | 110 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 109 insertions(+), 1 deletion(-) diff --git a/src/informatik_3.typ b/src/informatik_3.typ index 532365c..4cd03ad 100644 --- a/src/informatik_3.typ +++ b/src/informatik_3.typ @@ -137,7 +137,15 @@ str = str + "!"; [find], [```cpp size_t pos = str.find("de"); ``` \ ```cpp if (pos == std::string::npos){} ```], [Strings vergleichen], [```cpp (str1 == str2) ```], ) -=== container +Möchte man z.B. Windows-Pfade angeben hat man das problem das `\` Escape sequenzen sind. Aus diesem Grund braucht man Raw-Strings: +```cpp +// Ohne Raw-String müssen alle \ mit \\ ersetzt werden. +std::string str = "C:\\Programm\\input.txt" +// Mit dem Raw-String kann der Pfad so gelassen werden. +std::string str_raw = R"(C:\Programm\input.txt)" +``` + +=== Container container sind arrays welche daten enthalten und nicht selbst mit array handeling (malloc, speicher freigeben) zu tun haben. ==== std::vector Beim vector wird im hintergrund ein Speicherbereich reserviert. Falls der user etwas ergenzen möchte wird noch etwas mehr reserviert als benötigt wird. Sollte viel mehr ergäntz werden, so muss ein neuer Speicherbereich reserviert werden die daten rüber kopiert werden und der alte Speicherbereich wieder freigeben werden. @@ -432,6 +440,106 @@ int main(){ ```] ) +=== Console I/O +==== Output +#table(columns: 1fr, [```cpp +#include +int main(){ + std::cout << "Hello " << "World" << std::endl; + return 0; +} +```]) +```cpp std::endl ``` ist fast das gleiche wie `"\n"`. + +*format* +#table(columns: 1fr, [```cpp +#include +int main(){ + int n{42}; + std::cout << n << std::endl; // Output: "42" + std::cout << std::hex << n << std::endl; // Output: "2a" + std::cout << n << std::endl; // Output: "2a" + std::cout << std::dec << n << std::endl; // Output: "42" + return 0; +} +```]) +- ```cpp std::hex ``` schaltet den Output in den Hexadezimal modus. +- ```cpp std::dec ``` schaltet den Output in den Dezimal modus. + +*float* +Um verschiedene float darstellungen zu machen braucht es ```cpp #include ```. +Bsp. mit: ```cpp +#include +#include +int main () { + double pi{3.14159265359}; + double c{299792.458}; + double G{6.67408e-11}; + + // code + + return 0; +} +``` + +#table(columns: (0.5fr, 1fr, 0.3fr), +[default \ ```cpp std::defaultfloat ```], [```cpp +std::cout << pi << std::endl; +std::cout << c << std::endl; +std::cout << G << std::endl; +```], [3.14159 \ 299792 \ 6.67408e-11], +[precision to 4 \ ```cpp std::setprecision(4) ```], [```cpp +std::cout << std::setprecision(4) << std::endl; +std::cout << pi << std::endl; +std::cout << c << std::endl; +std::cout << G << std::endl; +```], [\ 3.142 \ 2.998e+05 \ 6.674e-11], +[Fixed comma \ ```cpp std::fixed ```], [```cpp +std::cout << std::fixed << std::endl; +std::cout << pi << std::endl; +std::cout << c << std::endl; +std::cout << G << std::endl; +```], [\ 3.1416 \ 299792.4580 \ 0.0000], +[Scientific notation \ ```cpp std::scientific ```], [```cpp +std::cout << std::scientific << std::endl; +std::cout << pi << std::endl; +std::cout << c << std::endl; +std::cout << G << std::endl; +```], [\ 3.1416e+00 \ 2.9979e+05 \ 6.6741e-11], +[Reset], [```cpp std::cout << std::defaultfloat; ```], [], +) + +==== Input + + +=== Stringstream +==== Output +==== Input + +=== File I/O +==== Output +==== Input + + +file append +std::ios::app +std::ofstream myfile("hello.txt", std::ios::app); + +=== Git +#table(columns: (0.8fr, 1fr), +[```sh git init ```], [Neues git repository erstellen], +[```sh git status ```], [Zeigt den status an. (geänderte files, etc)], +[```sh git add ```], [`my_file.py` zum repository hinzufügen], +[```sh git mv ```], [file umbeneänen oder verschieben], +[```sh git rm ```], [file aus der versionierung löschen], +[```sh git rm -f ```], [file aus der versionierung *und dem PC* löschen], +[```sh git commit -m "msg" ```], [Erstellt einen commit mit mit der Nachricht], +[```sh git revert ```], [ein altes File wiederherstellen], +[```sh git branch ```], [Zweigt alle branches an], +[```sh git branch ```], [erstellt einen neuen branch], +[```sh git branch -d ```], [löscht den branch], +[```sh git checkout ```], [in den branch wechseln], +) === testing ```cpp