Advertisement
Caminhoneiro

Vectors

Apr 18th, 2018
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.71 KB | None | 0 0
  1. // ConsoleApplication1.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <iostream>
  6. #include "ConsoleApplication1.h"
  7. #include <vector>
  8. #include <algorithm>
  9. #include <functional>
  10. #include <string>
  11.  
  12. using namespace std;
  13.  
  14.  
  15. int main()
  16. {
  17.     vector<int> ;
  18.  
  19.  
  20.     vector<string>::iterator myIterator; //identify a particular element in a container //Here you can change the item it gets
  21.    
  22.     vector<string>::const_iterator iter; //Here is a ready only iterator you cant modify the item he gets
  23.  
  24.  
  25.     vector<string> inventory;
  26.  
  27.     inventory.push_back("Sword");
  28.     inventory.push_back("Shit");
  29.     inventory.push_back("Pombo");
  30.    
  31.  
  32.     //cout << inventory.size();
  33.  
  34.     //for (int i = 0; i < inventory.size(); i++) {
  35.     //  cout << inventory[i] << "\n";
  36.     //}
  37.  
  38.     //inventory[2] = "POMBAO";
  39.  
  40.     //for (int i = 0; i < inventory.size(); i++) {
  41.     //  cout << inventory[i] << "\n";
  42.     //}
  43.  
  44.     //inventory.pop_back(); //Remove the last item on inventory
  45.  
  46.  
  47.     //for (int i = 0; i < inventory.size(); i++) {
  48.     //  cout << inventory[i] << "\n";
  49.     //}
  50.  
  51.     //inventory.clear() // Remove everything
  52.  
  53.     //Looping through a Vector with iterator
  54.  
  55.     //print the size:
  56.     //(*iter).size()
  57.  
  58.  
  59.     //
  60.  
  61.     myIterator = inventory.begin(); //set myIterator to reference the first element of inventory
  62.     *myIterator = "battle axe"; //change the value of the first element
  63.     cout << myIterator->size() << " letters in it.\n";
  64.     inventory.insert(inventory.begin(), "crossbow");
  65.     inventory.erase((inventory.begin() + 2)); //Remove
  66.  
  67.     for (iter = inventory.begin(); iter != inventory.end();
  68.         ++iter)
  69.         cout << (*iter).size() << endl;
  70.  
  71.  
  72.     return 0;
  73. }
  74.  
  75.  
  76.  
  77. //Dont shoot hes not b
  78. //https ://www.youtube.com/watch?v=GDYJO-1IhN8
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement