一个工程里只能有一个main函数,不同文件的函数之间可以相互调用,写个头文件就可以
下面举个例子介绍:
main.cpp
#include <iostream>
# include "trytry.h" /*包含的头文件*/
using namespace std;
int hello();
int main(){
cout << "hello" << endl;
nihao();
ssmai();
return 0;
}
int hello()
{
cout << "Hello world!" << endl;
return 0;
}
try.cpp
#include <iostream>
#include "trytry.h"/*自己的头文件*/
using namespace std;
int nihao()
{
cout << "你好!" << endl;
return 0;
}
trytry.h
#ifndef __FUNCTION_H__
#define __FUNCTION_H__
int nihao();/*在这里把所有想调用的函数写上*/
#endif