Sorry I'm new here, so I might not be posting this correctly, tips for next time would be appreciated. I'm having a problem with my delete string script within my program, here's the code:
//program to input a list of names, display them, sort them, and edit the list.
#include <iostream>
#include <vector>
#include <string>
using namespace std;
void getnames(vector<string>&);
void displaynames(vector<string>&);
void sortnames(vector<string>& names);
void removename(string name,vector<string>& names);
void swap(int& x, int& y);
int main() {
vector<string> names;
string name;
while (true) {//while loop to keep program running
string choice;
cout<<endl;
cout<<"Enter function you wish to use"<<endl;
cout<<"(getnames,displaynames,sortnames,findname,removename,quit): ";
cin>>choice;
if (choice=="getnames"){//if option to get input
getnames (names);
system ("PAUSE");
}
if (choice=="displaynames") {//if option to display names
displaynames (names);
system ("PAUSE");
}
if (choice=="sortnames"){//if option to sort the names by alphabetically
sortnames (names);
system ("PAUSE");
}
if (choice=="removename"){//if option to delete a name from the list
cout<<"Enter Name to Remove";
getline(cin,name);
removename (names, name);
system ("PAUSE");
}
if (choice=="quit") {break;}//if option to quit the program
}
return 0;
}
void getnames (vector<string>& names) {//input names for the vector
while (true) {
string name;
cout<<"Enter a name (quit to stop): ";
cin>>name;
if (name == "quit") break;
names.push_back(name);
}
}
void displaynames (vector<string>& names) {//displaying the names in order
int i;
for(i=0; i<names.size();i++){
cout<<names[i]<<endl;
}
cout<<i<<" names entered"<<endl;
}
void swap(int& x, int& y)//simple swap function
{
int temp;
temp=x;
x=y;
y=temp;
}
void sortnames(vector<string>& names) { //sorting the names in alphabetical order
for (int i = 1; i < names.size(); i++)
for (int j = 0; j < names.size() - i; j++)
if (names[j] > names[j+1]) swap(names[j], names[j+1]);
}
void removename (string Name, vector<string>& names) {//removing a name
for (int i=0; i!=names.size(); i++)
{
if (names[i].Name == name)
{
names.erase(names.begin()+i,names.begin()+1+i);
break;
}
}
}
and my error codes:
In function int main()': 40 conversion from std::vector<std::string, std::allocator<std::string> >' to non-scalar type std::string' requested In function
void removename(std::string, std::vector<std::string, std::allocator<std::string> >&)':
85 'struct std::basic_string<char, std::char_traits<char>, std::allocator<char> >' has no member named 'Name'
85 `name' undeclared (first use this function)