C++中的.h和.cpp如何关联

以下是.h和.cpp以及主程序三段,如何关联;//NameFunction.h#include<string>#include<vector>usingnamespace... 以下是.h和.cpp以及主程序三段,如何关联;

//NameFunction.h
#include<string>
#include<vector>
using namespace std;
//======================================
void FillVectors(vector<string> &name,vector<string> $origins);
string AskUserForName();
bool SearchForName(vector<string> &names,vector<string> &origins,string &userName,string &userOrigin);

//NameFunctions.cpp
#include<iostream>
#include<string>
#include<vector>
using namespace std;
//======================================================================================================
bool SearchForName(vector<string> &names,vector<string> &origins,string &userName,string &userOrigin)
{
for(int index=0;index<names.size();index++)
{
if(userName==names.at(index)){userOrigin=origins.at(index);return true;}
}
return false;
}
//=======================================================================================================
void FillVectors(vector<string> &name,vector<string> &origins)
{
name.push_back("Barbara");
origins.push_back("greek,meaning stranger");

name.push_back("Kelly");
origins.push_back("celtic,meaning warrior or defender");
}
//=======================================================================================================
string AskUserForName()
{
string userName;
cout<<"Please enter a women's name,such as Kelly;"<<endl;
cin>>userName;
return userName;
}
//=======================================================================================================

//============================================================================
#include<iostream>
#include<string>
#include<vector>
using namespace std;

#include "NameFunctions.h"

//=========================================================
int main()
{
cout<<"Welcome to C++ Name Search Program"<<endl;
vector<string> names,origins;
FillVectors(names,origins);//用函数对定义的两个vector对象赋值;

string userName,userOrigin,answer="yes";
bool Found;//判断是否找到;
for(;answer=="yes"||answer=="Yes";)
{
userName=AskUserForName();
Found=SearchForName(names,origins,userName,userOrigin);
if(Found)
{
cout<<"Here is your name: "<<userName<<endl;
cout<<"Origin: "<<userOrigin<<endl;
}
else{cout<<" Sorry "<<userName<<" isn't in our vector."<<endl;}
cout<<"Do you have another name? yes/no ";
cin>>answer;
}
return 0;
}
展开
 我来答
zwh202342
2010-02-02 · TA获得超过971个赞
知道大有可为答主
回答量:1417
采纳率:0%
帮助的人:1282万
展开全部
文件的关联性是在生成makefile文件生成的,然后编译器根据makefile提供的文件路径内容进行编译。生成exe二进制可执行文件。
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式