0

I am making some kind of phonebook that contains a person's name, phonenumber, profession, birth place and date. My problem is that i want the data to be stored in a Txt file, but the main problem is that i need a reader class and a writer class for it. If the txt file inside looked like

Firstname(can contain space);Lastname(can contain space);Phonenumber;etc;

How should i read these strings one by one and pass it to my contact?

... Here is a part of my class for contacts with setters and getters

 #include "Contacts.h"
 #include string

Contacts::Contacts() {}

std::string Contacts::setFirstname(std::string firstName) {
this->firstName = firstName;
}

std::string Contacts::getFirstname() {
    return firstName;
}

std::string Contacts::setLastname(std::string lastName) {
    this->lastName = lastName;
}

std::string Contacts::getLastname() {
    return lastName;
}

...In an other class(which has several operations for contacts like add,remove) i made a dynamic array of contacts, so every time i add a new contact the size of the array increases

So i would read datas from/expect a txt file that looks like this inside after output:

John;Wick Jr;123401234;Paris;1990.01.13;Engineer;

Enrique Juan;Iglesias;123401234;Madrid;1980.11.21;Surgeon;
noone0011
  • 1
  • 2
  • 1
    [`std::string`](https://en.cppreference.com/w/cpp/string/basic_string) and [`std::getline`](https://en.cppreference.com/w/cpp/string/basic_string/getline) and loops are the main things you need to solve this. – Some programmer dude Apr 02 '19 at 22:59
  • Rather than reader and writer classes (or providing the backbone for a reader and writer classes if you have to make classes) consider instead overloading `>>` and `<<` for `Contact`. Some help on how best to do that can be found at[What are the basic rules and idioms for operator overloading?](https://stackoverflow.com/questions/4421706/what-are-the-basic-rules-and-idioms-for-operator-overloading) – user4581301 Apr 02 '19 at 23:13
  • What have you tried, and why doesn't it work? Or, what is it that you're looking for (i.e. tools/methods to use to do this, or what kind of logic you would need to use, etc.)? – Andria Apr 02 '19 at 23:34

0 Answers0