lehrkraefte:blc:informatik:ffprg2-2024:cpp:start

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
lehrkraefte:blc:informatik:ffprg2-2024:cpp:start [2024/09/20 09:16] Ivo Blöchligerlehrkraefte:blc:informatik:ffprg2-2024:cpp:start [2024/10/18 06:48] (current) Ivo Blöchliger
Line 1: Line 1:
 +====== C++ für die SOI ======
 +  * Siehe auch https://soi.ch/wiki/stdlib/
 +  * und vor allem https://soi.ch/wiki/soi-vscode/ 
 +  * [[lehrkraefte:blc:informatik:ffprg2-2024:vorlage|Einstiegsaufgabe]]
 +  * [[.:vector|Arrays mit ''vector'']]
 +  * [[lehrkraefte:blc:informatik:ffprg2-2024:longest-increasing-subsequence|Aufgabe mit Arrays]]
 +
 +
 +<code bash>
 +cd
 +cd soi
 +mkdir hello
 +code .
 +</code>
 +
 +<WRAP todo>
 +Wenn Visual Studio Code nicht in der PATH Variablen und der Befehl ''code .'' darum nicht funktioniert:
 +
 +Finden Sie dazu den Pfad, wo Visual Studio code unter Windows installiert ist (sollte ''C:\Users\{Username}\AppData\Local\Programs\Microsoft VS Code'' sein, wobei ''{Username}'' entsprechend zu ersetzen ist).
 +
 +Erweitern Sie die Windows PATH Variable, dann funktioniert das Kommando ''code .'' auch in den Windows Kommandozeile. Siehe [[https://www.architectryan.com/2018/03/17/add-to-the-path-on-windows-10/|PATH Variable unter Windows 10 und 11 erweitern]].
 +
 +
 +Alternativ könnte man das auch auf Linux-Kommandozeile lösen, ist dann aber nur für Linux. Öffnen Sie die Datei ''~/.bashrc'':
 +<code bash>
 +nano ~/.bashrc
 +</code>
 +und fügen Sie am Schluss folgende Zeile mit dem korrekten Pfad zu VSCode an:
 +<code bash>
 +alias code="'/mnt/c/Users/{Username}/AppData/Local/Programms/Microsoft VS Code/code.exe'"
 +</code>
 +</WRAP>
 +
 +  * Neue Datei hello.cpp anlegen mit Inhalt
 +
 +<code cpp>
 +#include <iostream>
 +using namespace std;
 +
 +int main() {
 +    int a, b;
 +    cin >> a >> b;
 +    int result = a + b;
 +    cout << result << '\n';
 +}
 +</code>
 +
 +Programm kompilieren, anzeigen und ausführen:
 +
 +<code bash>
 +g++ hello.cpp -o hello
 +ls
 +./hello
 +</code>
 +Geben Sie zwei Zahlen durch einen Abstand getrennt ein und bestätigen Sie. 
 +
 +
 +===== Datenfiles für die Aufgabendaten =====
 +<code txt eingabe.txt>
 +19 23
 +</code>
 +Verwenden mit
 +<code bash>
 +# Eingabe aus Datei, Ausgabe auf Terminal
 +./hello < eingabe.txt 
 +
 +# Eingabe aus Datei, Ausgabe in Datei ausgabe.txt
 +./hello < eingabe.txt > ausgabe.txt
 +
 +# Ausgabe sowohl auf Terminal wie in Datei ausgabe.txt
 +./hello < eingabe.txt | tee ausgabe.txt
 +</code>