Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <vector>
- #include <iostream>
- int main() {
- vector<int> myVector; //This vector will contain int values
- int number;
- do {
- cout << "Feed me numbers! 0 to end! ";
- cin >> number;
- myVector.push_back(number); //This function puts the number at the end of the vector
- } while (number!=0);
- for (auto i=myVector.begin();i!=myVector.end();i++) //Loop with pointers
- cout << *i << endl;
- for (int i{};i<myVector.size();i++) //Loop with index
- delete myVector[i]; //In this case it's not needed, but if each object within the vector has been allocated memory, delete it.
- myVector.clear(); //Clearing the content of the vector.
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement