C++ 随机字符串生成函数

2015-06-23 0 684
C++ 随机字符串生成函数
//C++ 随机字符串生成函数
#include<iostream>
#include<ctime>
using namespace std;

const int LEN_NAME=4;

char *rand_str(char *str,const int len)
{
    int i;
    for(i=0;i<len;++i)
        str[i]='A'+rand()%26;
    str[++i]='\0';
    return str;
}

void main()
{
    srand(time(NULL));
    int i;
    char name[LEN_NAME+1];

    for(i=0;i<20;++i)
    {
        cout<<rand_str(name,LEN_NAME)<<endl;
    }
}

遇见资源网 c/c++ C++ 随机字符串生成函数 http://www.ox520.com/10174.html

常见问题

相关文章

发表评论
暂无评论
官方客服团队

为您解决烦忧 - 24小时在线 专业服务