平时上网的时候会看到很多的验证码,手机验证的时候也经常收到短信验证码,今天,就来实现一下这个功能,仅仅是一些代码片段,仅供参考。
// 2015021101.cpp : Defines the entry point for the console application.
//
#include
"stdafx.h"
#include
"time.h"
#include
"stdlib.h"
#include
"iostream"
using
namespace
std
;
int
_tmain
(
int
argc
,
_TCHAR
*
argv
[
])
{
const
char
*
pszSource
=
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
;
const
char
*
pszDigital
=
"0123456789"
;
static
time
_t
nSeed
=
0
;
if
(
0
==
nSeed
)
{
time
(
&
nSeed
)
;
srand
((
unsigned
int
)
nSeed
)
;
}
int
nLen
=
strlen
(
pszSource
)
;
char
pszPassWd
[
7
]
=
{
0
}
;
for
(
int
i
=
0
;
i
<
sizeof
(
pszPassWd
) /
sizeof
(
pszPassWd
[
0
])
;
i
++
)
{
pszPassWd
[
i
]
=
pszSource
[
rand
(
)
%
nLen
]
;
}
pszPassWd
[
6
]
=
0
;
cout
<<
pszPassWd
<<
endl
;
return
0
;
}