Click here to Skip to main content
15,890,186 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
What's going is when i run it i get this error that says "main.obj : error LNK2019: unresolved external symbol "void __cdecl WriteToFile(void)" (?WriteToFile@@YAXXZ) referenced in function "void __cdecl addContact(void)" (?addContact@@YAXXZ)" and i also get one that says "C:\Users\Anikan\Documents\Visual Studio 2010\Projects\ContactBook\Debug\ContactBook.exe : fatal error LNK1120: 1 unresolved externals". If you have any advice on what i can do to fix this all help will be appreciated!

C++
#include <iostream>
#include <fstream>
#include <string>

using namespace std;

void addContact();
void removeContact();
void editContact();
void WriteToFile();

string GetName();
string GetAdress();

int main()
{
	int yesNo;
	int ansChoice;

	do{
	cout << "Here are your choices: " << endl;
	cout << "  1. Create a Contact" << endl;
	cout << "  2. Remove a Contact" << endl;
	cout << "  3. Edit a Contact" << endl;
	cout << "  0. Exit" << endl;
	cin >> ansChoice;

	switch(ansChoice)
	{
	case 1:
		addContact();
		break;
	case 2:
		removeContact();
		break;
	case 3:
		editContact();
		break;
	case 0:
		cout << "Goodbye!" << endl;
		break;
	default:
		cout << "Goodbye!" << endl;
		break;
	}

	cout << "Do you need to do another modification?(1 for yes, 0 for no): ";
	cin >> yesNo;

	}while(yesNo);
}

void addContact()
{
	string FullName, PersonAdress;
	int getDateOfBirthYear, getDateOfBirthDay, getDateOfBirthMonth;
	long getPhoneNumber;

	FullName = GetName();
	PersonAdress = GetAdress();

	cout << "Now Enter the year " << FullName << "'s was born in: ";
	cin >> getDateOfBirthYear;
	cout << "Now the Month: ";
	cin >> getDateOfBirthMonth;
	cout << "And the Day: ";
	cin >> getDateOfBirthDay;
	cout << "\n" << "Please enter their phone number: ";
	cin >> getPhoneNumber;

	WriteToFile();
}

void WriteToFile(string FullName, string PersonAdress, int getDateOfBirthYear, int getDateOfBirthDay, int getDateOfBirthMonth, long getPhoneNumber)
{
	ofstream contactFile (FullName);
	if(contactFile.is_open())
	{
		contactFile << "Name: " << FullName << "\n";
		contactFile << "Adress: " << PersonAdress << "\n";
		contactFile << "Date of Birth: " << getDateOfBirthMonth << "/" << getDateOfBirthDay << "/" << getDateOfBirthYear << "\n";
		contactFile << "Phone Number: " << getPhoneNumber << "\n";
	}
	else{
		cout << "Error 23 Contact your Administrator :D." << endl;
	}

	//return 0;
}
void removeContact()
{

}
void editContact()
{

}
string GetName(){
	
	string FirstName, LastName, FN;

	cout << "Person's First Name: ";
	cin >> FirstName;
	cout << "Person's last Name: ";
	cin >> LastName;

	FN = FirstName + " " + LastName;

	return FN;
}
string GetAdress(){

	int adressNumber;
	string streetName, Fin;

	cout << "Please enter the name of the Street: ";
	cin >> streetName;
	cout << "Now enter the adress number: ";
	cin >> adressNumber;

	Fin = adressNumber + " " + streetName;

	return(Fin);
}
Posted
Updated 22-Jun-12 6:55am
v2

It means that you are making a call to method WriteToFile(void) that's declared at the top, but not implemented anywhere.

In your code you implemented version of WriteToFile that takes several parameters, but you do not have implementation for one without parameters, that which you are trying to call, hence the unresolved reference.
 
Share this answer
 
v4
Comments
Anikan1297 22-Jun-12 18:13pm    
But i did implement in the code, in the addContact method at the bottom, and can you put that last part of what you said into a more beginner word set please?
Vitaly Tomilov 22-Jun-12 19:46pm    
What did you implement? You did not implement WriteToFile(void)! You just call the method that HAS NO IMPLEMENTATION. Read your own code, please!
Anikan1297 22-Jun-12 20:13pm    
Sir, may i ask why you are so anxious? I mean appreciate your help, but no reason to get angry. Could you also keep in mind that i am a BEGINNER!!!!!
Vitaly Tomilov 22-Jun-12 20:17pm    
Sorry, but I'm under impression you do not understand what word implementation means in programming. In that case read the meaning of function declaration vs implementation vs invocation. There is no implementation in your code for that method.
Add parameter list in the declaration of function WriteToFile
Pass the values of name, address etc to the function in the function call WriteToFile()
 
Share this answer
 
When compiling and linking read the error messages carefully.


Anikan1297 wrote:
error LNK2019: unresolved external symbol "void __cdecl WriteToFile(void)"
(?WriteToFile@@YAXXZ) referenced in function "void __cdecl addContact(void)"


This tells you all you need to know. You are missing void WriteToFile(void). You are missing it because it was called in void addContact(void) and there is no implementation for it in your code.


Anikan1297 wrote:
C:\Users\Anikan\Documents\Visual Studio
2010\Projects\ContactBook\Debug\ContactBook.exe : fatal error LNK1120: 1
unresolved externals".


This now says that the link failed because of one unresolved external. Of course.

If you add:

C++
void WriteToFile(void)
{

}


the program will link.

It will not work properly until you insert the intended code into the body of this function.
 
Share this answer
 
v5
Change the prototype on top to

void WriteToFile(string FullName, string PersonAdress, int getDateOfBirthYear, int getDateOfBirthDay, int getDateOfBirthMonth, long getPhoneNumber);

and

modify the call to WriteToFile() - within addContact() - to
WriteToFile(FullName, PersonAdress, getDateOfBirthYear, getDateOfBirthDay, getDateOfBirthMonth, getPhoneNumber);
 
Share this answer
 
Comments
enhzflep 3-Jul-12 9:36am    
Nearly..
You forgot to change the call to the ofstream's constructor.

I.e
ofstream contactFile (FullName);
should be
ofstream contactFile (FullName.c_str());
Amarnath S 3-Jul-12 13:08pm    
Thanks. Yes - I missed this out. Thanks for pointing.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900