通讯录循环错误 [英] Contact Book Loop error

查看:124
本文介绍了通讯录循环错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我运行它时,发生的事情是我收到此错误,该错误表示"main.obj:错误LNK2019:未解决的外部符号"void __cdecl WriteToFile(void)"(?WriteToFile @@ YAXXZ)在函数"void"中引用__cdecl addContact(void)(?addContact @@ YAXXZ)",我还得到一个说"C:\ Users \ Anikan \ Documents \ Visual Studio 2010 \ Projects \ ContactBook \ Debug \ ContactBook.exe的错误:致命错误LNK1120:1未解决的外部".如果您对我能做些什么来解决此问题有任何建议,将不胜感激!

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!

#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);
}

推荐答案

这意味着您正在调用顶部声明的方法WriteToFile(void),但未在任何地方实现. br/>
在您的代码中,实现了带有多个参数的WriteToFile版本,但是您没有实现没有参数的实现,而要尝试调用的则没有参数.
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.


在函数WriteToFile的声明中添加参数列表
将名称,地址等值传递给函数调用WriteToFile()中的函数
Add parameter list in the declaration of function WriteToFile
Pass the values of name, address etc to the function in the function call WriteToFile()


在编译和链接时,请仔细阅读错误消息.


When compiling and linking read the error messages carefully.


Anikan1297写道:
Anikan1297 wrote:

错误LNK2019:未解决的外部符号"void __cdecl WriteToFile(void)"
函数"void __cdecl addContact(void)"中引用(?WriteToFile @@ YAXXZ)

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



这告诉您所有您需要知道的.您缺少void WriteToFile(void).您会丢失它,因为它是在void 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写道:
Anikan1297 wrote:

C:\ Users \ Anikan \ Documents \ Visual Studio
2010 \ Projects \ ContactBook \ Debug \ ContactBook.exe:致命错误LNK1120:1
尚未解决的外部因素".

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:

void WriteToFile(void)
{

}



该程序将链接.

除非您将所需的代码插入到此函数的主体中,否则它将无法正常工作.



the program will link.

It will not work properly until you insert the intended code into the body of this function.


这篇关于通讯录循环错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆