您的位置:首页 > 编程语言 > C语言/C++

C++_生成随机字符串

2013-03-21 14:39 246 查看
#include<iostream>
#include<ctime>
using namespace std;

const int LEN_NAME=10;

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

void main()
{
srand((unsigned)time(NULL));
char name[LEN_NAME+1];
cout<<rand_str(name,LEN_NAME)<<endl;
}


若出现Stack around the variable ‘name’ was corrupted,就把project->配置属性->c/c++->代码生成->基本运行时检查改为默认值。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: