So you want the n last cards ? Then maintain a "last n cards" list and update it for every card found.
Like that : (code written by hand)
#include <list>
#include <string>
std::list<std::string> last_n_cards;
const unsigned int last_n_cards_max = 2;
// basic init to make code simpler, can be done differently
last_n_cards.push_back( "?" ); // too lazy to write the for(last_n_cards_max) loop ;)
last_n_cards.push_back( "?" );
(loop)
if( line.find(search_str) != std::string::npos )
{
currentCard = line.substr(4);
cout << currentCard << '\n';
last_n_cards.push_back(currentCard); // at new card to the end
last_n_cards.pop_front(); // remove 1 card from the front
}
// At the end :
cout << "Last two cards are : " << last_n_cards[0] << " and " << last_n_cards[1] << '\n';
std::list
API is here http://en.cppreference.com/w/cpp/container/list
Note : have you considered using another language than C++ for this task ? Non perf-intensive files parsing may be easier with a dynamic language like python.