Question: Can someone help me fix these errors in the C++ code? I am getting a jump to case label [-fpermissive] when the switch statements begin,

Can someone help me fix these errors in the C++ code?

I am getting a jump to case label [-fpermissive] when the switch statements begin, a crosses initialization of 'Person person' error,cannot convert 'std::vector::iterator {aka __gnu_cxx::__normal_iterator >}' to 'const char*' for argument '1' to 'int remove(const char*)' main.cpp

#include

#include

#include

using namespace std; #include "Person.h"

int menu(); int find(vector, string); //function to update the data to file every time void writeToFile(ofstream& , vector);

int main() { // Container for holding all Person objects. vector people; ofstream out("information.txt"); while(true) { int choice = menu(); PersonDetails p; string name; int index; switch(choice) { case 1: cout<<"Enter name: "; cin>>p.name; cout<<" Enter phone: "; cin>>p.phone; cout<<" Enter address: "; cin>>p.address; cout<<" Enter email: "; cin>>p.email; cout<<" Enter website: "; cin>>p.website; Person person(p); people.push_back(person); writeToFile(out, people); break; case 2: cout<<" Enter name to search: "; cin>>name; index = find(people, name); if(index<0) cout<<" Person not found "; else cout<>name; index = find(people, name); if(index<0) cout<<" Person not found "; else people.erase(remove(people.begin(), people.end(), index), people.end()); writeToFile(out, people); break; case 4: exit(0); } } return 0; }

int menu() { int choice; //add a person to the text file where names/addresses/etc. are stored cout << "1. Add Person" << endl; //search the text file for a name and it will return all of the person's info cout << "2. Search Directory" << endl; //removes a person's entry from the text file along with all of their personal data cout << "3. Remove Person" << endl; //exits from the program cout << "4. Exit" << endl; cout<<" Enter your choice: "; cin>>choice; return choice; }

// Finds a person and returns it index. int find(vector pv1, string name) { for (unsigned int i = 0; i < pv1.size(); ++i) { if (pv1.at(i).get_name() == name) { return i; } } return -1; }

void writeToFile(ofstream& out, vector people) { for(int i=0; iPerson.h

#ifndef PERSON_H_ #define PERSON_H_

#include using namespace std;

struct PersonDetails { string name, phone, address, email, website; };

class Person { private: string _name; string _phone; string _address; string _email; string _website; public: Person(); Person(PersonDetails p1); virtual ~Person();

string get_name();

friend ostream & operator << (ostream &, Person &); };

#endif /* PERSON_H_ */

Person.cpp

#include "Person.h" #include

Person::Person() { // Init all _name = ""; _phone = ""; _address = ""; _email = ""; _website = ""; }

Person::Person(PersonDetails pd1) { _name = pd1.name; _phone = pd1.phone; _address = pd1.address; _email = pd1.email; _website = pd1.website; }

Person::~Person() {}

string Person::get_name() { return this->_name; }

ostream & operator << (ostream &os, Person &p1) { os << p1._name; return os; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!