add output and git
This commit is contained in:
parent
93b20dedba
commit
05c27f1304
@ -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 <iostream>
|
||||
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 <iostream>
|
||||
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 <iomanip> ```.
|
||||
Bsp. mit: ```cpp
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
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> ```], [`my_file.py` zum repository hinzufügen],
|
||||
[```sh git mv <alter_name.py> <neuer_name.py> ```], [file umbeneänen oder verschieben],
|
||||
[```sh git rm <my_file.py> ```], [file aus der versionierung löschen],
|
||||
[```sh git rm -f <my_file.py> ```], [file aus der versionierung *und dem PC* löschen],
|
||||
[```sh git commit -m "msg" ```], [Erstellt einen commit mit mit der Nachricht],
|
||||
[```sh git revert <file> ```], [ein altes File wiederherstellen],
|
||||
[```sh git branch ```], [Zweigt alle branches an],
|
||||
[```sh git branch <neuer_branch>```], [erstellt einen neuen branch],
|
||||
[```sh git branch -d <branch>```], [löscht den branch],
|
||||
[```sh git checkout <branch> ```], [in den branch wechseln],
|
||||
)
|
||||
|
||||
=== testing
|
||||
```cpp
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user