多文件程序不能运行是什么原因?

来源:百度知道 编辑:UC知道 时间:2024/09/27 23:32:44
这是function.h文件
#include <string>
using namespace std;

{
void writehello();
string askforname();
int askforage();
void write(string name,int age);
return 0;
}
这是function.cpp程序
#include <iostream>
#include <string>
using namespace std;
void writehello()
{cout<<"\nhello from a c++ function!\n";
}
int askforage()
{

int age;
cout<<"\n how old are you?";
cin>>age;
cin.ignore();
return age;
}

string askforname()
{string name;
cout<<"\n what is your name?";
getline(cin,name);
return name;}
void write(string name,int age)
{cout<<"\n hi"<<name<<"!you are"<<age<<"years old.\n";}
这是diver.cpp程序文件
#include <iostream>
#include <string>
#includ

(1) 头文件里怎么出现 return 语句?
应当只有声明和原型声明。例如:

#include <string>
using namespace std;
void writehello();
string askforname();
int askforage();
void write(string name,int age);

(2) 你说: "这是function.h文件"
#include "Functions.h" 应当是 #include "function.h"

(3)必要时function.cpp 要加 #include "functions.h"
并且用宏保护起来,避免多次include.