-
August 23rd, 2010, 06:39 PM
#16
Re: for loop question
Originally Posted by exdox77
Are you kidding me I should known that. Arrays get me every time well thanks everyone for your help. Next step is to try the vector and grow my array as I input people. Any ideas to start from.
I'm new to STL, but this worked for me:
#include <vector>
vector<string> deck; //creates string vector called 'deck'
vector<string>::iterator VecIt; //creates string iterator called VecIt
deck.push_back("2s"); //assigns values to vector - spades
deck.push_back("3s");
deck.push_back("4s");
deck.push_back("5s");
deck.push_back("6s");
deck.push_back("7s");
deck.push_back("8s");
deck.push_back("9s");
deck.push_back("Ts");
deck.push_back("Js");
deck.push_back("Qs");
deck.push_back("Ks");
deck.push_back("As");
----------------------------------------------------------------------------------------------------
I was creating a vector that would let me enter strings of cards and their suit. To remove an element I did this (it worked, but not sure if it's the most efficient way):
VecIt =remove(deck.begin(), deck.end(), deck[y]); //uses iterator to remove y from deck.
deck.erase(VecIt, deck.end()); //erases y from deck
------------------------------------------------------------------------------------------------------
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|