Experts,
I am having one heck of a time trying to get something to print out using cout. Here is a description of the application that I am writing. Basically it is a contact management app that will allow a user to add, edit, delete contacts as they so choose. They can have multiple contact books which they can "open" and do whatever they want.
The problem is that in our class we have to use polymorphism inheritance and all is good. It took me a while to figure out an error with fstream but once I got that worked out my application works smoothly.
The problem is that when I call
/* Use to pass cout as a reference */
_contacts->ViewFile(0, cout);
or
/* Does not pass cout as reference */
_contacts->ViewFile(0);
once I start trying to output anything on the screen it basically overwrites what is there. Here is the function ViewFile.
void Contacts::ViewFile(int contactNum, ostream& obj)
{
/* String to hold line */
string _outLine;
/* Check contactNum */
//if (contactNum > this->_iperson.size() - 1)
//contactNum = this->_iperson.size() - 1;
this->ShowInfo();
Person& _person = _iperson[0];
_outLine.append("Name:\t\t
");
_outLine.append(this->_ipe
rson[conta
ctNum].Las
tName);
_outLine.append(", ");
_outLine.append(this->_ipe
rson[conta
ctNum].Fir
stName);
_outLine.append(" ");
_outLine.append(this->_ipe
rson[conta
ctNum].Mid
dleName);
_outLine.append("\n");
cout.write(_outLine.c_str(
), _outLine.size());
return;
/* Loop through contact addresses */
if (_iperson[0].Addresses.siz
e() > 0)
{
cout << "Address(es):\t";
for (int a = 0; a < _iperson[0].Addresses.size
(); a++)
{
/* Insert tabs if not first address */
if (a != 0) cout << "\t\t";
/* Output location and country */
cout << _iperson[0].Addresses[a].A
ddressLoca
tion << " - " << _iperson[0].Addresses[a].C
ountry << endl;
/* Output address 1 and 2 */
cout << endl << "\t\t" << _iperson[0].Addresses[a].A
ddress1;
if (_person.Addresses[a].Addr
ess2 != "")
cout << endl << "\t\t" << _iperson[0].Addresses[a].A
ddress2;
/* Output city, State Zip Code */
cout.write("Test", string("Test").size());
cout << endl << "\t\t" << _iperson[0].Addresses[a].C
ity << ", "
<< _iperson[0].Addresses[a].S
tate << " "
<< _iperson[0].Addresses[a].Z
ipCode << endl;
}
}
}
Now here is the trick. this->ShowInfo() prints out on the screen fine. It is only AFTER I start making any calls to _iperson[contactNum] that it starts printing out at the beginning of the line no matter what is before or after.
So if I called
cout << _iperson[contactNum].First
Name << _iperson[contactNum].LastN
ame
it would print out
Bullard
cause my last name is longer than the first. So I don't understand why this is happening.
Any help would be greatly appreciated. :)