   Need advice on how to print an number array and a vector of strings at the same time.
  Well, Im almost finished a little text based RPG i was doing, only thing left was to allow the plaer to use the potions they bought in combat. The problem is the user inputs numbers to determine thier choice and the inventory items are printed in strings and the vector is constantly changing with buying/using the items, so i needed some sort of system for counting how many elements the vector contained and printing the number before each vector element. E.G1. Potion2. Large potionI tried writing a for loop within the function but I haven't covered the STL too much so im not sure what you can do with the vectors and also i only briefly looked at the new operator so im not entierley sure what you can do with it.void use_inventory(enemy &players_enemy,family_member &player){const int inventory_number_size = player.player_inventory.size();int * inventory_numbers =  new int[inventory_number_size];vector<std::string>::const_iterator inv_iter;cout<<"--------------------------------------"<<endl;cout<<"   Inventory"<<endl;cout<<"--------------------------------------"<<endl;for(inv_iter = player.player_inventory.begin();inv_iter != player.player_inventory.end();inv_iter ++){ int i; cout<<inventory_numbers;  i ++; cout<<*inv_iter<<endl;    }    bool valid_choice = false;  std::string choice;    while(valid_choice == false){cout<<"Type the name of the item you want to use: ";cin>>choice;}}With that i get errors like :  Access violation reading location and i don't know how to set about doing this task (Does this mean i am a bad programmer). Any help would be greatly appreciated.thanks :)   
  You're not initializing your integer, and every time through the for loop it will be recreated.Now, if you just want the position within the vector you can simply use:(inv_iter - player.player_inventory.begin())which will give you the 0 based index into player.player_inventory.Furthermore, you're not initializing your array elements (that you allocated), and so they will contain garbage. lastly, after allocating that array you do not delete it, so you are leaking memory.   ;  Thanks for the help and I will certianly give it a shot. I do not understand the part of taking the first element away from an iterator part. I don't see how that could give you it's current position. Could you explain a little more?   ;Quote:Original post by KyleMThanks for the help and I will certianly give it a shot. I do not understand the part of taking the first element away from an iterator part. I don't see how that could give you it's current position. Could you explain a little more?Sure, we're obtaining the distance from the current element pointed to by the iterator inv_iter from the beginning of the vector. This can also be obtained through the standard library function distance:std::vector<std::string>::difference_type pos = std::distance(player.player_inventory.begin(), inv_iter);The above is a more standard method to do it with generic iterator types, and will return the number of times the first iterator must be incremented to equal the second iterator. However the vector type provides iterators of the type known as "random access iterators". Which can be subtracted from each other.You can read more about this here and here.Any decent book on the C++ standard library should also cover this, such as The C++ Standard Library: A tutorial and reference by Josuttis.   ;  Ow could I use this to print the elements choice number on the same line.   ;Quote:Original post by KyleMOw could I use this to print the elements choice number on the same line.for(itor = inventory.begin(); itor != inventory.end(); ++itor) {    std::cout<<(itor - inventory.begin())<<": "<<*itor<<std::endl;}when given the inventory of:["Hammer", "Shield", "Monkey's Head"]will print:0: Hammer1: Shield2: Monkey's Head;  Oh sorry, you already said. Thanks I'll hive it a goEDIT: what exactly does the begin() member function return? The contents of the first element?  Or something else.   ;  if you're using a vector, you could do:for(int = 1; i <= inventory.size(); i++) {    std::cout<<(i <<": "<<inventory.at(i)<<std::endl;}I don't know quite what an iterator is (I'm guessing some sort of pointer that knows what size it is), so that's the only reason I'd do it my way.Not sure of the performance ramifications of either.edit: why does my thing not let me do the pretty code snippets? :(   ;Quote:Original post by KyleMOh sorry, you already said. Thanks I'll hive it a goEDIT: what exactly does the begin() member function return? The contents of the first element?  Or something else.On a container, such as vector, the begin() method returns an iterator pointing to the beginning of the vector. This happens to be covered in the links I gave you earlier.   ;Quote:Original post by way2lazy2careI don't know quite what an iterator is (I'm guessing some sort of pointer that knows what size it is)An iterator is the generalization of a pointer pointing into an array -- it marks some position within a container.   