I have a structure containing

struct XboxFriends
{
	char gamertag[SIZE];
	char name[SIZE];
	char country[SIZE];
	char city[SIZE];
	char favoriteGames[SIZE];
	int age;
};

this code is supposed to keep track of my xbox friends. I also have written a function

void searchFriends(vector<XboxFriends> &friends)
{
	string gameName;
	cout << "--- Favorite Game Search ---\n\n";
	cout << "Search Keyword: ";
	cin.ignore();
	getline(cin, gameName);
	
		for(unsigned int i=0; i<friends.size(); i++)
	{
		if (gameName == friends[i].favoriteGames)
			cout << friends[i].gamertag << endl;			
	}
	cout << endl;
	cout << endl;
}

This code is supposed to search through my friends favorite games and if they match they return the gamertag name. I realize that right now my code is just comparing the input to the whole string and returning the gamertags of those that match. I was just wondering if anyone could give me some advice on how to search the string for just keywords and still return the gamertags of those that match?

look at the various "find" functions that are part of the string class.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.