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

Differences

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

Link to this comparison view

lehrkraefte:blc:informatik:ffprg2-2024:cpp:vector [2024/09/23 11:11] – created Ivo Blöchligerlehrkraefte:blc:informatik:ffprg2-2024:cpp:vector [2024/09/23 11:15] (current) Ivo Blöchliger
Line 1: Line 1:
 +====== Arrays mit vector ======
  
 +<code c++>
 +#include <iostream>
 +#include <vector>
 +
 +using namespace std;
 +
 +int main() {
 +    vector<int> v;
 +    v.push_back(3); // [3]
 +    v.push_back(2); // [3,2]
 +    v.push_back(5); // [3,2,5]
 +    for (int i=0; i<v.size(); i++) {
 +        cout << v[i] << ",";
 +    }
 +    cout << endl; 
 +    
 +    // Ohne Index:
 +    for (auto x : v) {
 +        cout << x << '\n';
 +    }    
 +}
 +</code>