Hi all I'm new to this forum - Hope you can help me with my problem.
First off all; I apologize for my poor english skills, i'm from sweeden
I'm trying to make a simple phonebook by using a vector of struct's.
As you can see in the code pasted below i'm having a hard time when trying to modify
data in my vector. eg. I want to change the address of Person[0]
Do i need to pass Person[0] from main - or can i just pass "person" and then return the modifed address to person[0] ? - How do i do this ?
Hope it makes sense
Heres what I have so far: (Just working on one element so far, person[0])
struct Book
{
std::string Name;
std::string Address;
int Phone;
};
void InsertData(vector<Book> &Insert)
{
Book x;
cout << "Enter name: ";
getline(cin,x.Name);
cout << "Enter address: ";
getline(cin,x.Address);
cout << "Enter phone number: ";
cin >> x.Phone;
Insert.push_back(x);
}
// Print element [0]
void Print(vector<Book> &PrintData)
{
cout << "\nName " << PrintData[0].Name
<< "\nAddress: " << PrintData[0].Address
<< "\nPhone: " << PrintData[0].Phone << "\n\n";
}
void ChangeAdr(vector<Book> &InsAdr)
{
Book x;
cin.ignore();
cout << "Enter new address: ";
getline(cin,x.Address);
// This is where I come up short
// How do I return the new adr. to Person[0]
}
int main(int argc, char *argv[])
{
vector<Book> Person;
InsertData(Person);
Print(Person);
ChangeAdr(Person);
Print(Person);
system("PAUSE");
return 0;
}
Thx in Advance
Kind regards Dan