Hi,
This project is for school, so error spotting only please. No solutions.
I'm trying to create a simple contact book in a text file with a console application. I've tried using headers iostream, fstream and ostream in every file just be sure that wasn't the problem, it still doesn't work.
This is what comes up in the error list after attempting to compile:
"1>------ Build started: Project: c++2_Final, Configuration: Debug Win32 ------
1> c++2_Final.cpp
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\ostream(604): error C2249: 'std::basic_ios<_Elem,_Traits>::operator =' : no accessible path to private member declared in virtual base 'std::basic_ios<_Elem,_Traits>'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\ios(177) : see declaration of 'std::basic_ios<_Elem,_Traits>::operator ='
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> This diagnostic occurred in the compiler generated function 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator =(const std::basic_ostream<_Elem,_Traits> &)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> Contact.cpp
1> Generating Code...
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped =========="
Here is my code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
|
//Contact.h
#pragma once
class Contact
{
public:
string name, phone, address, email;
ofstream myFile;
void writeFile();
};
//Contact.cpp
void Contact::writeFile()
{
myFile.open(name + ".txt");
myFile << "Name:" + name << endl;
myFile << "Phone number:" + phone << endl;
myFile << "Address:" + address << endl;
myFile << "Email address:" + email << endl;
myFile.close();
}
//main.cpp
int _tmain(int argc, _TCHAR* argv[])
{
vector<Contact> contact(10);
bool eof = false;
string checkAddContact;
int contactNumber = 0;
while(eof == false)
{
cout << "Please enter name:" << endl;
cin >> contact[contactNumber].name;
cout << "Please enter phone:" << endl;
cin >> contact[contactNumber].phone;
cout << "Please enter address:" << endl;
cin >> contact[contactNumber].address;
cout << "Please enter email:" << endl;
cin >> contact[contactNumber].email;
contact[contactNumber].writeFile();
cout << "Would you like to enter another contact? y/n" << endl;
cin >> checkAddContact;
contactNumber++;
if(contactNumber > 9)
{
eof = true;
}
if(checkAddContact == "y")
{
eof = false;
}
else
{
eof = true;
}
}
return 0;
}
| |