Created
May 21, 2019 22:11
-
-
Save Thiago4532/cc01e27ebe40b4ef34062c8e753b6455 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <vector> // Biblioteca que contem a estrutura vector | |
| using namespace std; | |
| int main() { | |
| vector<int> v; // Declaracao de um vector do tipo int | |
| // No inicio o vetor esta vazio | |
| v.push_back(1); // Insiro o elemento 1 no final do vetor | |
| v.push_back(3); // Insiro o elemento 3 no final do vetor | |
| v.push_back(5); // Insiro o elemento 5 no final do vetor | |
| v.push_back(7); // Insiro o elemento 7 no final do vetor | |
| for(int i = 0; i < (int)v.size(); i++) { // Comando v.size() diz o número de elementos no vetor. | |
| cout << v[i] << " "; // Imprimo o i-ésimo elemento do vetor | |
| } | |
| cout << "\n"; | |
| // Saída: | |
| // 1 3 5 7 | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment