嘿嘿嘿,你绝对看得懂这个教程!
大家好,我是妙眼看世界!今天,小编接到大家的几个问题,现在就像小伙伴们介绍创建头文件的教程。怎么创建头文件呢?其实啊,解决这个问题非常简单,我们只需要一台电脑、一个Dev-C++或者Visual Studio就可以了。当然呢,你也需要一个电源、一个鼠标、一个键盘、一个屏幕、一双眼睛、一个大脑……
咳咳,言归正传,怎么创建一个头文件?
看:
打开Dev,新建项目
然后,保存(废话)
删光光。
加入新手喜欢的。
#include <bits/stdc++.h>
using namespace std;
int main()
{
return 0;
}
然后在左侧列表新建。
重命名。
命名为你的头文件名+.h
FBI是头文件名,加上.h
之后,点OK。
然后,再加入一段:
#ifndef _STL_ALGOBASE_H
#define _STL_ALGOBASE_H 1
#include <bits/c++config.h>
#include <bits/functexcept.h>
#include <bits/cpp_type_traits.h>
#include <ext/type_traits.h>
#include <ext/numeric_traits.h>
#include <bits/stl_pair.h>
#include <bits/stl_iterator_base_types.h>
#include <bits/stl_iterator_base_funcs.h>
#include <bits/stl_iterator.h>
#include <bits/concept_check.h>
#include <debug/debug.h>
#include <bits/move.h> // For std::swap and _GLIBCXX_MOVE
namespace std _GLIBCXX_VISIBILITY(default)
{
_GLIBCXX_BEGIN_NAMESPACE_VERSION
#if __cplusplus < 201103L
// See http://gcc.gnu.org/ml/libstdc++/2004-08/msg00167.html: in a
// nutshell, we are partially implementing the resolution of DR 187,
// when it's safe, i.e., the value_types are equal.
template<bool _BoolType>
struct __iter_swap
{
template<typename _ForwardIterator1, typename _ForwardIterator2>
static void
iter_swap(_ForwardIterator1 __a, _ForwardIterator2 __b)
{
typedef typename iterator_traits<_ForwardIterator1>::value_type
_ValueType1;
_ValueType1 __tmp = _GLIBCXX_MOVE(*__a);
*__a = _GLIBCXX_MOVE(*__b);
*__b = _GLIBCXX_MOVE(__tmp);
}
};
当然不是这个啦!!!
看下面的:
#include <bits/stdc++.h>
using namespace std;
之后,自定义一个函数,可以是int、void、char、string……当然,名字不能叫main。 就像在普通代码里的函数一样,别忘记return。
接下来,如果你想直接在普通cpp调用,而不是放在项目里调用,只需要干下面的事情(可以不看):
随便新建一个cpp(普通),输入以下:
#include <bits/stdc++.h>
using namespace std;
int main()
{
int a,b,c;
a=b=c=0;
cout<<max(a,b,c);
return 0;
}
编译一下,如果报错,祝贺你!!!右键标签上的,然后打开文件夹。
把你的头文件放到文件夹里就行了!
好了,我们继续。做完一个头文件,Ctrl+S保存。然后回到main,在头文件加入下列语句:
#include "FBI.h"
当然,要用你自己的头文件的名字。不能使用<>,要用""。
之后,在你的main里就能用你的函数啦!
我演示一下: