#include<iostream>
#include<vector>
usingnamespace std;
vector <string> names;
//Getting the values from user for vector
void getNames(string tmp)
{
while (true)
{
cout << "Enter a name (quit to stop): ";
cin >> tmp;
cout<<endl;
if (tmp == "quit")
break;
names.push_back(tmp);
}
}
//displaying Vector elements
void displayNames()
{
for(int i=0;i<(names.size());i++)
cout<<"string = "<<names.at(i)<<endl;
cout<<endl;
}
//finding a specific element in vector
void findNames()
{
string x,found;
cout<<"please string to find";
cin>>x;
find(names.begin(), names.end(), x);
}
//erasing specific element from vector
void removeNames()
{
displayNames();
int index;
cout<<"enter index to remove the element for vector";
cin>>index;
names.erase(names.begin()+(index-1));
displayNames();
}
//sorting vector elements list
void sortNames()
{
sort (names.begin(), names.end());
cout<<"Sorted Vector List is"<<endl;
displayNames();
}
main()
{
//Declaration of a character type variable to for actions
char ch;
//Declaration of string type varible to accept strings or elements for vector
string tmp;
getNames(tmp);
//prompting the user to enter the choice to choose the action to be done on vector list
cout<<"enter your choice"<<endl;
cout<<"'s' for sort, 'd' for display, 'r' for remove, 'f' for find the string";
cin>>ch;
if(ch=='s')
sortNames();
elseif(ch=='d')
displayNames();
elseif(ch=='r')
removeNames();
elseif(ch=='f')
findNames();
system("pause");
}
i just want to do that
user will enter a string to find and the findNames() function will diaplay that
string is found and at position of vector.
I want to display the position of founded string in the vectorlist
please help
thanks..