cryptography.h
#pragma once
void getVerCode();
cryptography.cpp
#include "cryptography.h"
#include<iostream>
#include<cstdlib>
#include<time.h>
#include<math.h>
using namespace std;
void getVerCode()
{
int _new;
int N = 99;
int _low = 0;
int _flag = 0;
int verCode[256]={}, _verCode[6]={};
for (int i = 1; i <= N; i++)
{
int flag = (rand() % 2 == 0) ? 1 : 0;
_low = _low ^ (flag << (i - 1));
}
for (int i = 1; i < 256; i++)
{
verCode[i] = (_low & 1);
_new = _low & 1 ^ ((_low >> 4) & 1);
_low = _low >> 1 ^ (_new << 4);
}
for (int i = 255; i > 0; i -= 5)
{
int x;
x = verCode[i] + verCode[i - 1] * 2 + verCode[i - 2] * 4 + verCode[i - 3] * 8;
if (x < 10)
{
_verCode[_flag] = x;
_flag++;
}
if (_flag >= 5)
{
break;
}
}
cout << "验证码为:";
for (int i = 0; i < 6; i++)
{
cout << _verCode[i];
}
}
main.cpp
#include"cryptography.cpp"
int main()
{
srand((unsigned)time(NULL));
int flag;
for (int i = 0; i < 10; i++)
{
getVerCode();
cout << endl;
}
cin >> flag;
return 0;
}
调试显示:
1>main.obj : error LNK2005: "void __cdecl getVerCode(void)" (?getVerCode@@YAXXZ) 已经在 cryptography.obj 中定义
1>C:\Users\Administrator\source\repos\WorkPacketForC++Course\x64\Debug\WorkPacketForC++Course.exe : fatal error LNK1169: 找到一个或多个多重定义的符号
1>已完成生成项目“WorkPacketForC++Course.vcxproj”的操作 - 失败。
请问如何解决?