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;
} 展开
//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;
} 展开
展开全部
#include "FileName.h"
其中FileName是你头文件的名字。
至于对应的.h和.cpp文件名字一样,那纯粹是命名习惯的问题。
其中FileName是你头文件的名字。
至于对应的.h和.cpp文件名字一样,那纯粹是命名习惯的问题。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
fuck!这么长,就给0分,没人给你答的!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
在CPP中#includeh文件就OK
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询