inline 关联函数直接调用代码而不是函数;
exit()在自己创建的函数里可直接退出
#include <iostream>
#include <vector>
using namespace std;
vector<int>A;
string type="int";
int num=0;//对数目
int p;//计算的量
bool judge;
bool cond2= 1;//两个bool类型
inline int check(int c)
{
judge = 0;
//先检查数目是否合理
if (num == (A.size()))
{
judge = 1;
}
if (!judge) {
cout << "error 1";
exit(1);
}
//在检查是否存在
for (int j = 0; j < A.size(); j++)
{
if (c== A[j])
{
cond2 = 0;
}
}
if (!cond2)
{
cout << "error 2";
exit(1);
}
A.push_back(c);
num++;
}
void fun1()
{
for (int n = 1; n <= 10; n++)
{
p = n * (3*n - 1) / 2;
check(p);
}
}
//这个函数就是用来算数的
void fun2(vector<int>A,string type_s)
{
for (int i = 0; i < A.size(); i++)
{
cout << A[i]<<" ";
}
cout << endl << type_s;
}
int main()
{
fun1();
fun2(A,type);
}