okay so my issue is that I want the user to enter in variables, which get added to list<string> Listings; . I then want the user to be able to search specifically for some thing that they added to the list, display what they searched for if it exists and then display the next five elements in the list.
I understand how to iterate through and display the entire contents of the list<string>
I understand how to search for a specific phrase or sentence etc.. using the std::find() or std::find_if()
What I need to know is how do I search for some thing and if it exists display not only it but say for example the next five variables that are stored in the list<string>.
The below code isn't the best but if I were to give you all my code you'd be here for ours lol... The basics are still the same though
#include "string"
#include "list"
#include "iostream"
#include "sstream"
#include "iterator"
usingnamespace std;
int main()
{
string Name = "";
string Listing = " Listing: ";
list<string> Listings;
string UserChoice;
cout << " Please enter a name for your listing " << endl;
cin.ignore();
getline(cin, Name);
Listings.push_back(Listing);
Listings.push_back(Name);
/* The user has entered a string which is then stored in
list<string> Listings; along with a default variable called
Listings */
// I could do some thing like the following but it doesn't do what I need it to
for(list<string>::iterator s = Listings.begin(); s != Listings.end(); s++)
{
cout << " " << *s;
}
// I'm thinking about some thing like this
if (s = find(Listings.begin(), s != Listings.end(), UserChoice));
cout << UserChoice << endl;
return 0;
}
Shouldn't I be able to do some thing like *S+=1; to move it to the next variable in the list, and then continue that process while displaying each item?
Yeah I just my mistake on that lol, I've tried so many different ways of doing this and I'm just missing some thing some where. The end result of how I want my information to output would be this.
Example Output 1
Example Output 2
Example Output 3
Example Output 4
Example Output 5
(I want them to be displayed at the same time)
I think the issue that I'm having is occurring when I try to move past the initial found variable.
How would I go about that, some thing like the following?
1 2 3 4 5 6 7 8 9
if((s = find(Listings.begin(),Listings.end(),UserChoice)) != Listings.end())
{
cout << UserChoice << endl;
*S += 1; /* I'd say ++S but i may not nessicarily just move one space I may move a few variables ahead */
cout << *S << endl; // Or would it be UserChoice still?
etc....
}
I've never tried to display multiple at the same time this way and I jsut can't figure it out lol
EDIT: So I was able to move the iterator forward and display the next item in Listings, sadly it removed the previous variable that was displayed.