Okay this is a staring point that shows your current level of ability, now to clean it up a little.
First when passing non-trivial classes (for example std::string) into functions it is usually a good idea to pass them into the functions by reference, const qualifying when appropriate, instead of by value as you are currently doing.
Second you should start using initialization lists with your constructors whenever possible.
Third you should strive to initialize class instances when you define them instead default initializing them and then using some method to alter their values. For example:
The following is a bad example:
1 2 3 4 5 6 7
|
...
ifstream in;
vector<address> addresses;
// out.open("phoneBook.txt",ofstream::app);
in.open("phoneBook.txt");
...
|
Normally you should prefer something more like:
1 2 3 4 5 6
|
...
vector<address> addresses;
...
ifstream in("phoneBook.txt"); // Prefer using the constructor whenever possible.
...
|
And note you should be defining your variables closer to first use, not in one big glob at the beginning of scopes. Also note that you really should be testing the stream for all errors, not just checking if the stream is open or not. Something more like
if(!in)
instead.
Fourth using using eof() to control a read loop will cause problems when not used correctly, such as how you're using it in this program. You should prefer to use the actual read operations to control the read loop.
1 2 3 4 5
|
...
while(getline(in,name))
{
// Do whatever.
...
|
So yeah I pretty much have the basics down now I want to write something that will challenge me(but not leave me pulling my hair out) and give me more confidence |
Okay since you want a C++ challenge you need to start thinking in C++, ie: use classes instead of structures (private data), using class methods (public accessors) instead of everything being non-class functions, etc.
Also, since you want more challenge your input file should not have every field on it's own line.
There is more but fixing the issues above will be a start.
This is a very very simple start you'll probably want to complicate things as you move along. You need to think about "real people", do these "real people" always have only one type of address where you contact them? Do you always need to go to their address to contact them? Etc., etc., etc.