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<<"Enter function you wish to use"<<endl;
          cout<<"(getnames,displaynames,sortnames,findname,removename,quit): ";
          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";
             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): ";
           if (name == "quit") break;

void displaynames (vector<string>& names) {//displaying the names in order
     int i;
     for(i=0; i<names.size();i++){
     cout<<i<<" names entered"<<endl;

void swap(int& x, int& y)//simple swap function
     int 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)

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 functionvoid 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)

Recommended Answers

All 4 Replies

I was wondering if anyone could tell me what I did wrong, I'm new to programming and I'm beyond lost.

on line 40 the parameters to removename() are reversed, you have them backwards.

slightly embarressed that I didn't catch that, thanks that got rid of a few errors, only the ones on line 86 remain.

Same problem as the previous one.

Be a part of the DaniWeb community

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