Skip to main content
gamedev.net
🔒 Locked

Using insert on a vector

Started by goonst 1 reply 400+ views
Original Post
goonst
goonst
I know this is a really easy thing but I'm just a beginner. Hopefully someone can easily steer me in the right direction. I'm making a Blackjack game and I'm trying to insert a cut card into a deck (which is a vector of cards) at a specific spot. Here's the function. void Shoe::insertCutCard(void) { Card cutCard; int iRandomNum = rand(); int iFifthOfDeck = vCards.size() * (1/5); int iSeventhOfDeck = vCards.size() * (1/7); cutCard.iSuit = 0; cutCard.iValue = 0; cutCard.bFacingUp = false; int iCutPos = (iRandomNum % (iFifthOfDeck - iSeventhOfDeck) + iFifthOfDeck); vCards.insert(iCutPos, cutCard); } I believe that I need to use a iterator when using insert but I cant find a good way to make an interator equal iCutPos. Any help on the matter would be much appreciated.
meatbeef
meatbeef
Yeah you need to get an iterator for the position.
 vCards.insert(vCards.begin()+iCutPos, cutCard);
goonst
goonst
Problem solved, thanks for the help =).

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.